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.



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_processedObject (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

#resultObject (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_processedObject (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