Class REXML::Source
In:
Parent: Object

A Source can be searched for patterns, and wraps buffers and other objects and provides consumption of text

Methods

consume   current_line   empty?   encoding=   match   match_to   match_to_consume   new   position   read   scan  

Included Modules

Attributes

buffer  [R]  The current buffer (what we’re going to read next)
encoding  [R] 
line  [R]  The line number of the last consumed text

Public Class methods

Constructor @param arg must be a String, and should be a valid XML document

[Source]

31:                 def initialize(arg)
32:                         @orig = @buffer = arg
33:                         self.encoding = check_encoding( @buffer )
34:                         @line = 0
35:                 end

Public Instance methods

[Source]

76:                 def consume( pattern )
77:                         @buffer = $' if pattern.match( @buffer )
78:                 end

@return the current line in the source

[Source]

106:                 def current_line
107:                         lines = @orig.split
108:                         res = lines.grep @buffer[0..30]
109:                         res = res[-1] if res.kind_of? Array
110:                         lines.index( res ) if res
111:                 end

@return true if the Source is exhausted

[Source]

97:                 def empty?
98:                         @buffer == ""
99:                 end

Inherited from Encoding Overridden to support optimized en/decoding

[Source]

39:                 def encoding=(enc)
40:                         super
41:                         @line_break = encode( '>' )
42:                         if enc != UTF_8
43:                                 @buffer = decode(@buffer)
44:                                 @to_utf = true
45:                         else
46:                                 @to_utf = false
47:                         end
48:                 end

[Source]

90:                 def match(pattern, cons=false)
91:                         md = pattern.match(@buffer)
92:                         @buffer = $' if cons and md
93:                         return md
94:                 end

[Source]

80:                 def match_to( char, pattern )
81:                         return pattern.match(@buffer)
82:                 end

[Source]

84:                 def match_to_consume( char, pattern )
85:                         md = pattern.match(@buffer)
86:                         @buffer = $'
87:                         return md
88:                 end

[Source]

101:     def position
102:       @orig.index( @buffer )
103:     end

[Source]

73:                 def read
74:                 end

Scans the source for a given pattern. Note, that this is not your usual scan() method. For one thing, the pattern argument has some requirements; for another, the source can be consumed. You can easily confuse this method. Originally, the patterns were easier to construct and this method more robust, because this method generated search regexes on the fly; however, this was computationally expensive and slowed down the entire REXML package considerably, since this is by far the most commonly called method. @param pattern must be a Regexp, and must be in the form of /^\s*(#{your pattern, with no groups})(.*)/. The first group will be returned; the second group is used if the consume flag is set. @param consume if true, the pattern returned will be consumed, leaving everything after it in the Source. @return the pattern, if found, or nil if the Source is empty or the pattern is not found.

[Source]

66:                 def scan(pattern, cons=false)
67:                         return nil if @buffer.nil?
68:                         rv = @buffer.scan(pattern)
69:                         @buffer = $' if cons and rv.size>0
70:                         rv
71:                 end

Search

Google

Ruby API Docs

Links