Class: OXM::SaxHandler
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- OXM::SaxHandler
- Defined in:
- lib/oxm/sax_handler.rb
Instance Attribute Summary collapse
-
#outputs ⇒ Object
readonly
Returns the value of attribute outputs.
Instance Method Summary collapse
- #cdata_block(str) ⇒ Object
- #characters(str) ⇒ Object
- #end_element(tag) ⇒ Object
-
#initialize(loop_node, &block) ⇒ SaxHandler
constructor
A new instance of SaxHandler.
- #match? ⇒ Boolean
- #start_element(tag, attributes) ⇒ Object
Constructor Details
#initialize(loop_node, &block) ⇒ SaxHandler
Returns a new instance of SaxHandler.
5 6 7 8 9 10 11 |
# File 'lib/oxm/sax_handler.rb', line 5 def initialize loop_node, &block @loop_node = loop_node @block = block = [] @objects = [] @outputs = [] end |
Instance Attribute Details
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
3 4 5 |
# File 'lib/oxm/sax_handler.rb', line 3 def outputs @outputs end |
Instance Method Details
#cdata_block(str) ⇒ Object
27 28 29 |
# File 'lib/oxm/sax_handler.rb', line 27 def cdata_block str @object.cdata = @object.to_s + str if @object end |
#characters(str) ⇒ Object
31 32 33 |
# File 'lib/oxm/sax_handler.rb', line 31 def characters str @object.content = @object.to_s + str if @object end |
#end_element(tag) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/oxm/sax_handler.rb', line 35 def end_element tag unless @objects.empty? if match? obj = @objects.pop if @block @block.call obj else @outputs << obj end @object = nil else @objects.pop @object = @objects.last end end .pop end |
#match? ⇒ Boolean
53 54 55 |
# File 'lib/oxm/sax_handler.rb', line 53 def match? .join('/') == @loop_node end |
#start_element(tag, attributes) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/oxm/sax_handler.rb', line 13 def start_element tag, attributes << tag # Met loop element if @objects.empty? if match? @objects << @object = OXM::Object.new(tag, Hash[*attributes.flatten]) end elsif @object @object.add_node tag, node_obj = OXM::Object.new(tag, Hash[*attributes.flatten]) @objects << @object = node_obj end end |