Class: StringScanner
Instance Attribute Summary collapse
-
#last ⇒ Object
readonly
Returns the value of attribute last.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#last ⇒ Object (readonly)
Returns the value of attribute last.
5 6 7 |
# File 'lib/rmtools/text/string_scanner.rb', line 5 def last @last end |
Class Method Details
.each(string, *args, &b) ⇒ Object
55 56 57 |
# File 'lib/rmtools/text/string_scanner.rb', line 55 def self.each string, *args, &b new string, *args, &b end |
Instance Method Details
#each(re, cbs = nil, &cb) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rmtools/text/string_scanner.rb', line 7 def each(re, cbs=nil, &cb) @last = 0 res = scan_until re if cbs if cbs.keys.compact[0].is Fixnum while res if cb = cbs[matched.ord] cb[self] @last = pos res = !eos? && scan_until(re) else break end end else while res if cb = cbs.find {|pattern, proc| pattern and pattern.in matched} # patterns must be as explicit as possible cb[1][self] @last = pos res = !eos? && scan_until(re) else break end end end else while res cb[self] @last = pos res = !eos? && scan_until(re) end end if (cb = cbs[nil]) and !eos? cb[tail] end end |
#head ⇒ Object
43 44 45 |
# File 'lib/rmtools/text/string_scanner.rb', line 43 def head string[@last...pos-matched.size] end |
#hl_next(re) ⇒ Object
51 52 53 |
# File 'lib/rmtools/text/string_scanner.rb', line 51 def hl_next(re) (res = scan_until re) && RMTools.hl(string[pos-1000..pos+1000], res) end |
#tail ⇒ Object
47 48 49 |
# File 'lib/rmtools/text/string_scanner.rb', line 47 def tail string[pos..-1] end |