Class: MultiXml::Parsers::Ox::Handler Private
- Inherits:
-
Object
- Object
- MultiXml::Parsers::Ox::Handler
- Defined in:
- lib/multi_xml/parsers/ox.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
SAX event handler that builds a hash tree while parsing
Instance Method Summary collapse
-
#attr(name, value) ⇒ void
private
Handle an attribute.
-
#cdata(value) ⇒ void
private
Handle CDATA content.
-
#end_element(_name) ⇒ void
private
Handle end of an element.
-
#error(message, line, column) ⇒ void
private
Handle parse errors.
-
#initialize ⇒ Handler
constructor
private
Create a new SAX handler.
-
#result ⇒ Hash?
private
Get the parsed result.
-
#start_element(name) ⇒ void
private
Handle start of an element.
-
#text(value) ⇒ void
private
Handle text content.
Constructor Details
#initialize ⇒ Handler
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new SAX handler
35 36 37 |
# File 'lib/multi_xml/parsers/ox.rb', line 35 def initialize @stack = [] end |
Instance Method Details
#attr(name, value) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Handle an attribute
69 70 71 |
# File 'lib/multi_xml/parsers/ox.rb', line 69 def attr(name, value) add_value(name.to_s, value) unless @stack.empty? end |
#cdata(value) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Handle CDATA content
83 |
# File 'lib/multi_xml/parsers/ox.rb', line 83 def cdata(value) = add_value(TEXT_CONTENT_KEY, value) |
#end_element(_name) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Handle end of an element
59 60 61 62 |
# File 'lib/multi_xml/parsers/ox.rb', line 59 def end_element(_name) strip_whitespace_content if current.key?(TEXT_CONTENT_KEY) @stack.pop end |
#error(message, line, column) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Handle parse errors
92 93 94 |
# File 'lib/multi_xml/parsers/ox.rb', line 92 def error(, line, column) raise ::Ox::ParseError, "#{} at #{line}:#{column}" end |
#result ⇒ Hash?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the parsed result
42 |
# File 'lib/multi_xml/parsers/ox.rb', line 42 def result = @stack.first |
#start_element(name) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Handle start of an element
48 49 50 51 52 53 |
# File 'lib/multi_xml/parsers/ox.rb', line 48 def start_element(name) @stack << {} if @stack.empty? child = {} add_value(name.to_s, child) @stack << child end |
#text(value) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Handle text content
77 |
# File 'lib/multi_xml/parsers/ox.rb', line 77 def text(value) = add_value(TEXT_CONTENT_KEY, value) |