Module: XMLScan::ElementProcessing

Defined in:
lib/xmlscan/processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pairsObject (readonly)

Returns the value of attribute pairs.



94
95
96
# File 'lib/xmlscan/processor.rb', line 94

def pairs
  @pairs
end

#parserObject (readonly)

Returns the value of attribute parser.



94
95
96
# File 'lib/xmlscan/processor.rb', line 94

def parser
  @parser
end

Instance Method Details

#<<(s) ⇒ Object



58
# File 'lib/xmlscan/processor.rb', line 58

def <<(s) @out << s end

#on_chardata(s) ⇒ Object



59
# File 'lib/xmlscan/processor.rb', line 59

def on_chardata(s) self << s end

#on_etag(name, s = nil) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/xmlscan/processor.rb', line 75

def on_etag(name, s=nil)
  if name.to_sym == @element
    # output a card (name, content, type)
    @pairs[@context] = [@out, @stack[-1][0], *@ex]
    # restore previous context from stack
    last = @stack.pop
    @context, @out, @ex = last.shift, last.shift, *last
  else self << s end
end

#on_stag_empty_end(name, s = nil, h = {}, *a) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/xmlscan/processor.rb', line 85

def on_stag_empty_end(name, s=nil, h={}, *a)
  if name.to_sym == @element

    key= h&&h[@key.to_s]||'*no-name*'
    ex = @extras.map {|e| h[e]}
    @pairs[key] = [[], @context, *ex]
  else self << s end
end

#on_stag_end(name, s, h, *a) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/xmlscan/processor.rb', line 60

def on_stag_end(name, s, h, *a)
  if name.to_sym == @element
    # starting a new context, first output our substitute string
    key= h&&h[@key.to_s]||'*no-name*'
    self << @tmpl.split('|').find {
      |x| !(/:\w[\w\d]*/ =~ x) || h[$&[1..-1].to_s] }.gsub(/:\w[\w\d]*/) {
        |m| h[m[1..-1]]
     }
    # then push the current context and initialize this one
    @stack.push([@context, @out, *@ex])
    @pairs[key] = nil # insert it when first seen
    @context = key; @out = []; @ex = @extras.map {|e| h[e.to_s]}
  else self << s end # pass through tags we aren't processing
end