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
- #cdata(str) ⇒ 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.
8 9 10 11 12 13 14 |
# File 'lib/xmlhasher/handler.rb', line 8 def initialize( = {}) @options = @stack = [] @transform_cache = {} super() end |
Instance Method Details
#attr(name, value) ⇒ Object
24 25 26 27 28 |
# File 'lib/xmlhasher/handler.rb', line 24 def attr(name, value) return if ignore_attribute?(name) || @stack.empty? @stack.last.attributes[transform(name)] = escape(value) end |
#cdata(str) ⇒ Object
34 35 36 |
# File 'lib/xmlhasher/handler.rb', line 34 def cdata(str) @stack.last.text = escape(str) end |
#end_element(_name) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/xmlhasher/handler.rb', line 38 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
20 21 22 |
# File 'lib/xmlhasher/handler.rb', line 20 def start_element(name) @stack.push(Node.new(transform(name))) end |
#text(value) ⇒ Object
30 31 32 |
# File 'lib/xmlhasher/handler.rb', line 30 def text(value) @stack.last.text = escape(value) end |
#to_hash ⇒ Object
16 17 18 |
# File 'lib/xmlhasher/handler.rb', line 16 def to_hash @hash || {} end |