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
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#outputs ⇒ Object
readonly
Returns the value of attribute outputs.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
- #cdata_block(str) ⇒ Object
- #characters(str) ⇒ Object
- #end_element(tag) ⇒ Object
- #error(str) ⇒ Object
-
#initialize(loop_node, &block) ⇒ SaxHandler
constructor
A new instance of SaxHandler.
- #match? ⇒ Boolean
- #start_element(tag, attributes) ⇒ Object
- #warning(str) ⇒ Object
Constructor Details
#initialize(loop_node, &block) ⇒ SaxHandler
Returns a new instance of SaxHandler.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/oxm/sax_handler.rb', line 7 def initialize loop_node, &block @loop_node = loop_node @block = block @tags = [] @objects = [] @outputs = [] @warnings = [] @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/oxm/sax_handler.rb', line 5 def errors @errors end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
3 4 5 |
# File 'lib/oxm/sax_handler.rb', line 3 def outputs @outputs end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
4 5 6 |
# File 'lib/oxm/sax_handler.rb', line 4 def warnings @warnings end |
Instance Method Details
#cdata_block(str) ⇒ Object
40 41 42 |
# File 'lib/oxm/sax_handler.rb', line 40 def cdata_block str @object.cdata = @object.to_s + str if @object end |
#characters(str) ⇒ Object
44 45 46 |
# File 'lib/oxm/sax_handler.rb', line 44 def characters str @object.content = @object.to_s + str if @object end |
#end_element(tag) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/oxm/sax_handler.rb', line 48 def end_element tag unless @objects.empty? obj = @objects.pop # Strip content if obj.cdata? obj.cdata = obj.to_s.strip else obj.content = obj.to_s.strip end obj.content = nil if obj.to_s.empty? if match? if @block @block.call obj else @outputs << obj end @object = nil else @object = @objects.last end end @tags.pop end |
#error(str) ⇒ Object
22 23 24 |
# File 'lib/oxm/sax_handler.rb', line 22 def error str @errors << str end |
#match? ⇒ Boolean
74 75 76 |
# File 'lib/oxm/sax_handler.rb', line 74 def match? @tags.join('/') == @loop_node end |
#start_element(tag, attributes) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/oxm/sax_handler.rb', line 26 def start_element tag, attributes @tags << 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 |
#warning(str) ⇒ Object
18 19 20 |
# File 'lib/oxm/sax_handler.rb', line 18 def warning str @warnings << str end |