Method: XMLScan::ElementProcessor#initialize

Defined in:
lib/xmlscan/processor.rb

#initialize(opts = {}, mod = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/xmlscan/processor.rb', line 16

def initialize(opts={}, mod=nil)
  raise "No module" unless mod
  (MY_METHODS - mod.instance_methods).each do |i|
    self.class.class_eval %{def #{i}(d, *a) d&&(self << d) end}, __FILE__, __LINE__
  end
  self.class.send :include, mod

  @element = opts[:element] || raise("need an element")
  @key = opts[:key] || raise("need a key")
  @extras = (ex = opts[:extras]) ? ex.map(&:to_sym) : []
  @tmpl = opts[:substitute] || "{{:key}}"

  @pairs = {}   # output name=> [content, context, extra_values] * 1 or more
  @context = '' # current key(name) of the element (card)
  @stack = []   # stack of containing context cards
  @out = []     # current output for name(card)
  @parser = XMLScan::XMLParser.new(self)
  self
end