Class: Serialbench::Serializers::Xml::SaxHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/serialbench/serializers/xml/rexml_serializer.rb

Overview

SAX handler for REXML streaming

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ SaxHandler

Returns a new instance of SaxHandler.



109
110
111
112
113
114
# File 'lib/serialbench/serializers/xml/rexml_serializer.rb', line 109

def initialize(&block)
  @block = block
  @elements_processed = 0
  @text_nodes_processed = 0
  @result = nil
end

Instance Attribute Details

#elements_processedObject (readonly)

Returns the value of attribute elements_processed.



107
108
109
# File 'lib/serialbench/serializers/xml/rexml_serializer.rb', line 107

def elements_processed
  @elements_processed
end

#resultObject (readonly)

Returns the value of attribute result.



107
108
109
# File 'lib/serialbench/serializers/xml/rexml_serializer.rb', line 107

def result
  @result
end

#text_nodes_processedObject (readonly)

Returns the value of attribute text_nodes_processed.



107
108
109
# File 'lib/serialbench/serializers/xml/rexml_serializer.rb', line 107

def text_nodes_processed
  @text_nodes_processed
end

Instance Method Details

#characters(text) ⇒ Object



121
122
123
124
125
126
# File 'lib/serialbench/serializers/xml/rexml_serializer.rb', line 121

def characters(text)
  return if text.strip.empty?

  @text_nodes_processed += 1
  @block&.call(:text, text)
end

#end_element(_uri, _localname, qname) ⇒ Object



128
129
130
# File 'lib/serialbench/serializers/xml/rexml_serializer.rb', line 128

def end_element(_uri, _localname, qname)
  @block&.call(:end_element, { name: qname })
end

#start_element(_uri, _localname, qname, attributes) ⇒ Object



116
117
118
119
# File 'lib/serialbench/serializers/xml/rexml_serializer.rb', line 116

def start_element(_uri, _localname, qname, attributes)
  @elements_processed += 1
  @block&.call(:start_element, { name: qname, attributes: attributes })
end