module XMLScan::ElementProcessing
Attributes
pairs[R]
parser[R]
Public Instance Methods
<<(s)
click to toggle source
# File lib/xmlscan/processor.rb 58 def <<(s) @out << s end
on_chardata(s)
click to toggle source
# File lib/xmlscan/processor.rb 59 def on_chardata(s) self << s end
on_etag(name, s=nil)
click to toggle source
# File lib/xmlscan/processor.rb 75 def on_etag(name, s=nil) 76 if name.to_sym == @element 77 # output a card (name, content, type) 78 @pairs[@context] = [@out, @stack[-1][0], *@ex] 79 # restore previous context from stack 80 last = @stack.pop 81 @context, @out, @ex = last.shift, last.shift, *last 82 else self << s end 83 end
on_stag_empty_end(name, s=nil, h={}, *a)
click to toggle source
# File lib/xmlscan/processor.rb 85 def on_stag_empty_end(name, s=nil, h={}, *a) 86 if name.to_sym == @element 87 88 key= h&&h[@key.to_s]||'*no-name*' 89 ex = @extras.map {|e| h[e]} 90 @pairs[key] = [[], @context, *ex] 91 else self << s end 92 end
on_stag_end(name, s, h, *a)
click to toggle source
# File lib/xmlscan/processor.rb 60 def on_stag_end(name, s, h, *a) 61 if name.to_sym == @element 62 # starting a new context, first output our substitute string 63 key= h&&h[@key.to_s]||'*no-name*' 64 self << @tmpl.split('|').find { 65 |x| !(/:\w[\w\d]*/ =~ x) || h[$&[1..-1].to_s] }.gsub(/:\w[\w\d]*/) { 66 |m| h[m[1..-1]] 67 } 68 # then push the current context and initialize this one 69 @stack.push([@context, @out, *@ex]) 70 @pairs[key] = nil # insert it when first seen 71 @context = key; @out = []; @ex = @extras.map {|e| h[e.to_s]} 72 else self << s end # pass through tags we aren't processing 73 end