Module: XmlNodeStream::Parser::Base
- Defined in:
- lib/xml_node_stream/parser/base.rb
Overview
This is the base parser syntax that normalizes the SAX callbacks by providing a common interface so that the actual parser implementation doesn’t matter.
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #do_cdata_block(characters) ⇒ Object
- #do_characters(characters) ⇒ Object
- #do_end_element(name) ⇒ Object
- #do_start_element(name, attributes) ⇒ Object
- #initialize(&block) ⇒ Object
- #parse_stream(io) ⇒ Object
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
7 8 9 |
# File 'lib/xml_node_stream/parser/base.rb', line 7 def root @root end |
Instance Method Details
#do_cdata_block(characters) ⇒ Object
35 36 37 |
# File 'lib/xml_node_stream/parser/base.rb', line 35 def do_cdata_block (characters) @nodes.last.append_cdata(characters) unless @nodes.empty? end |
#do_characters(characters) ⇒ Object
31 32 33 |
# File 'lib/xml_node_stream/parser/base.rb', line 31 def do_characters (characters) @nodes.last.append(characters) unless @nodes.empty? end |
#do_end_element(name) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/xml_node_stream/parser/base.rb', line 24 def do_end_element (name) node = @nodes.pop node.finish! @root = node if @nodes.empty? @parse_block.call(node) if @parse_block end |
#do_start_element(name, attributes) ⇒ Object
19 20 21 22 |
# File 'lib/xml_node_stream/parser/base.rb', line 19 def do_start_element (name, attributes) node = XmlNodeStream::Node.new(name, @nodes.last, attributes) @nodes.push(node) end |
#initialize(&block) ⇒ Object
9 10 11 12 13 |
# File 'lib/xml_node_stream/parser/base.rb', line 9 def initialize (&block) @nodes = [] @parse_block = block @root = nil end |
#parse_stream(io) ⇒ Object
15 16 17 |
# File 'lib/xml_node_stream/parser/base.rb', line 15 def parse_stream (io) raise NotImplementedError.new("could not load gem") end |