Module: XMLScan::ElementProcessor

Includes:
Visitor
Included in:
XMLProcessor
Defined in:
lib/xmlscan/processor.rb

Constant Summary collapse

SKIP =
[:on_chardata, :on_stag, :on_etag, :on_attribute, :on_attr_entityref,
:on_attr_value, :on_start_document, :on_end_document, :on_attribute_end,
:on_stag_end, :on_stag_end_empty, :on_attr_charref, :on_attr_charref_hex]
MY_METHODS =
XMLScan::Visitor.instance_methods.to_a - SKIP

Instance Method Summary collapse

Methods included from Visitor

#on_attr_charref, #on_attr_charref_hex, #on_attr_entityref, #on_attr_value, #on_attribute, #on_attribute_end, #on_cdata, #on_chardata, #on_charref, #on_charref_hex, #on_comment, #on_doctype, #on_end_document, #on_entityref, #on_etag, #on_pi, #on_prolog_space, #on_stag, #on_stag_end, #on_stag_end_empty, #on_start_document, #on_xmldecl, #on_xmldecl_encoding, #on_xmldecl_end, #on_xmldecl_key, #on_xmldecl_other, #on_xmldecl_standalone, #on_xmldecl_version, #parse_error, #valid_error, #warning, #wellformed_error

Instance Method Details

#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