Class: SaxStream::Internal::MapperHandler
- Inherits:
-
Object
- Object
- SaxStream::Internal::MapperHandler
- Defined in:
- lib/sax_stream/internal/mapper_handler.rb
Overview
Handles SAX events on behalf of a mapper class. Expects the first event to be start_element, and then uses other events to build the element until end_element is received, at which time the completed object will be sent off to the collector.
Also handles child elements which use their own mapper class, and will pass off SAX control to other handlers to achieve this.
Instance Attribute Summary collapse
-
#collector ⇒ Object
readonly
Returns the value of attribute collector.
-
#mapper_class ⇒ Object
readonly
Returns the value of attribute mapper_class.
-
#stack ⇒ Object
Returns the value of attribute stack.
Instance Method Summary collapse
- #cdata_block(string) ⇒ Object
- #characters(string) ⇒ Object
- #current_object ⇒ Object
- #end_element(name) ⇒ Object
-
#initialize(mapper_class, collector, handler_stack, element_stack = ElementStack.new) ⇒ MapperHandler
constructor
- mapper_class
-
A class which has had SaxStream::Mapper included in it.
- #maps_node?(node_name) ⇒ Boolean
- #start_element(name, attrs = []) ⇒ Object
Constructor Details
#initialize(mapper_class, collector, handler_stack, element_stack = ElementStack.new) ⇒ MapperHandler
- mapper_class
-
A class which has had SaxStream::Mapper included in it.
- collector
-
The collector object used for this parsing run. This gets passed around to everything that needs it.
- handler_stack
-
The current stack of Sax handling objects for this parsing run. This gets passed around to everything that needs it. This class does not need to push itself onto the stack, that has already been done for it. If it pushes other handlers onto the stack, then it will no longer be handling SAX events itself until they get popped off.
- element_stack
-
Used internally by this object to collect XML elements that have been parsed which may be used when mapping this class. You don’t need to pass this in except for dependency injection purposes.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sax_stream/internal/mapper_handler.rb', line 28 def initialize(mapper_class, collector, handler_stack, element_stack = ElementStack.new) raise ArgumentError, "no collector" unless collector raise ArgumentError, "no mapper class" unless mapper_class raise ArgumentError, "no handler stack" unless handler_stack raise ArgumentError, "no element stack" unless element_stack @mapper_class = mapper_class @collector = collector @element_stack = element_stack @stack = handler_stack end |
Instance Attribute Details
#collector ⇒ Object (readonly)
Returns the value of attribute collector.
13 14 15 |
# File 'lib/sax_stream/internal/mapper_handler.rb', line 13 def collector @collector end |
#mapper_class ⇒ Object (readonly)
Returns the value of attribute mapper_class.
13 14 15 |
# File 'lib/sax_stream/internal/mapper_handler.rb', line 13 def mapper_class @mapper_class end |
#stack ⇒ Object
Returns the value of attribute stack.
12 13 14 |
# File 'lib/sax_stream/internal/mapper_handler.rb', line 12 def stack @stack end |
Instance Method Details
#cdata_block(string) ⇒ Object
52 53 54 |
# File 'lib/sax_stream/internal/mapper_handler.rb', line 52 def cdata_block(string) characters(string) end |
#characters(string) ⇒ Object
56 57 58 |
# File 'lib/sax_stream/internal/mapper_handler.rb', line 56 def characters(string) @element_stack.record_characters(string) end |
#current_object ⇒ Object
60 61 62 |
# File 'lib/sax_stream/internal/mapper_handler.rb', line 60 def current_object @current_object end |
#end_element(name) ⇒ Object
48 49 50 |
# File 'lib/sax_stream/internal/mapper_handler.rb', line 48 def end_element(name) pop_element_stack(name) || end_current_object(name) end |
#maps_node?(node_name) ⇒ Boolean
40 41 42 |
# File 'lib/sax_stream/internal/mapper_handler.rb', line 40 def maps_node?(node_name) @mapper_class.maps_node?(node_name) end |
#start_element(name, attrs = []) ⇒ Object
44 45 46 |
# File 'lib/sax_stream/internal/mapper_handler.rb', line 44 def start_element(name, attrs = []) start_current_object(name, attrs) || start_child_node(name, attrs) || start_child_data(name, attrs) end |