Class: Saxerator::Parser::Accumulator
- Inherits:
-
SaxHandler
- Object
- SaxHandler
- Saxerator::Parser::Accumulator
- Defined in:
- lib/saxerator/parser/accumulator.rb
Instance Method Summary collapse
- #accumulating? ⇒ Boolean
- #characters(string) ⇒ Object
- #end_element(_) ⇒ Object
-
#initialize(config, block) ⇒ Accumulator
constructor
A new instance of Accumulator.
- #start_element(name, attrs = []) ⇒ Object
Constructor Details
#initialize(config, block) ⇒ Accumulator
Returns a new instance of Accumulator.
4 5 6 7 8 |
# File 'lib/saxerator/parser/accumulator.rb', line 4 def initialize(config, block) @stack = [] @config = config @block = block end |
Instance Method Details
#accumulating? ⇒ Boolean
27 28 29 |
# File 'lib/saxerator/parser/accumulator.rb', line 27 def accumulating? !@stack.empty? end |
#characters(string) ⇒ Object
23 24 25 |
# File 'lib/saxerator/parser/accumulator.rb', line 23 def characters(string) @stack[-1].add_node(string) unless string.strip.empty? end |
#end_element(_) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/saxerator/parser/accumulator.rb', line 14 def end_element(_) if @stack.size > 1 last = @stack.pop @stack[-1].add_node last else @block.call(@stack.pop.block_variable) end end |
#start_element(name, attrs = []) ⇒ Object
10 11 12 |
# File 'lib/saxerator/parser/accumulator.rb', line 10 def start_element(name, attrs = []) @stack.push @config.output_type.new(@config, name, Hash[attrs]) end |