Class: XmlHasher::Handler
- Inherits:
-
Ox::Sax
- Object
- Ox::Sax
- XmlHasher::Handler
- Defined in:
- lib/xmlhasher/handler.rb
Instance Method Summary collapse
- #attr(name, value) ⇒ Object
- #end_element(name) ⇒ Object
-
#initialize(options = {}) ⇒ Handler
constructor
A new instance of Handler.
- #start_element(name) ⇒ Object
- #text(value) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Handler
Returns a new instance of Handler.
6 7 8 9 |
# File 'lib/xmlhasher/handler.rb', line 6 def initialize( = {}) @options = @stack = [] end |
Instance Method Details
#attr(name, value) ⇒ Object
19 20 21 22 23 |
# File 'lib/xmlhasher/handler.rb', line 19 def attr(name, value) unless ignore_attribute?(name) @stack.last.attributes[transform(name)] = escape(value) unless @stack.empty? end end |
#end_element(name) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/xmlhasher/handler.rb', line 29 def end_element(name) if @stack.size == 1 @hash = @stack.pop.to_hash else node = @stack.pop @stack.last.children << node end end |
#start_element(name) ⇒ Object
15 16 17 |
# File 'lib/xmlhasher/handler.rb', line 15 def start_element(name) @stack.push(Node.new(transform(name))) end |
#text(value) ⇒ Object
25 26 27 |
# File 'lib/xmlhasher/handler.rb', line 25 def text(value) @stack.last.text = escape(value) end |
#to_hash ⇒ Object
11 12 13 |
# File 'lib/xmlhasher/handler.rb', line 11 def to_hash @hash || {} end |