Class: Serialbench::Serializers::Xml::SaxHandler
- Inherits:
-
Object
- Object
- Serialbench::Serializers::Xml::SaxHandler
- Defined in:
- lib/serialbench/serializers/xml/rexml_serializer.rb
Overview
SAX handler for REXML streaming
Instance Attribute Summary collapse
-
#elements_processed ⇒ Object
readonly
Returns the value of attribute elements_processed.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#text_nodes_processed ⇒ Object
readonly
Returns the value of attribute text_nodes_processed.
Instance Method Summary collapse
- #characters(text) ⇒ Object
- #end_element(_uri, _localname, qname) ⇒ Object
-
#initialize(&block) ⇒ SaxHandler
constructor
A new instance of SaxHandler.
- #start_element(_uri, _localname, qname, attributes) ⇒ Object
Constructor Details
#initialize(&block) ⇒ SaxHandler
Returns a new instance of SaxHandler.
116 117 118 119 120 121 |
# File 'lib/serialbench/serializers/xml/rexml_serializer.rb', line 116 def initialize(&block) @block = block @elements_processed = 0 @text_nodes_processed = 0 @result = nil end |
Instance Attribute Details
#elements_processed ⇒ Object (readonly)
Returns the value of attribute elements_processed.
114 115 116 |
# File 'lib/serialbench/serializers/xml/rexml_serializer.rb', line 114 def elements_processed @elements_processed end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
114 115 116 |
# File 'lib/serialbench/serializers/xml/rexml_serializer.rb', line 114 def result @result end |
#text_nodes_processed ⇒ Object (readonly)
Returns the value of attribute text_nodes_processed.
114 115 116 |
# File 'lib/serialbench/serializers/xml/rexml_serializer.rb', line 114 def text_nodes_processed @text_nodes_processed end |
Instance Method Details
#characters(text) ⇒ Object
128 129 130 131 132 133 |
# File 'lib/serialbench/serializers/xml/rexml_serializer.rb', line 128 def characters(text) return if text.strip.empty? @text_nodes_processed += 1 @block&.call(:text, text) end |
#end_element(_uri, _localname, qname) ⇒ Object
135 136 137 |
# File 'lib/serialbench/serializers/xml/rexml_serializer.rb', line 135 def end_element(_uri, _localname, qname) @block&.call(:end_element, { name: qname }) end |
#start_element(_uri, _localname, qname, attributes) ⇒ Object
123 124 125 126 |
# File 'lib/serialbench/serializers/xml/rexml_serializer.rb', line 123 def start_element(_uri, _localname, qname, attributes) @elements_processed += 1 @block&.call(:start_element, { name: qname, attributes: attributes }) end |