Class: ActiveSupport::XmlMini_OxSAX::Handler
- Defined in:
- lib/rfm/xml_mini/ox_sax.rb
Instance Attribute Summary collapse
-
#stack ⇒ Object
Returns the value of attribute stack.
Instance Method Summary collapse
- #append(key, value) ⇒ Object
- #attr(name, value) ⇒ Object
- #cdata(value) ⇒ Object
- #doc ⇒ Object
- #end_element(name) ⇒ Object
- #error(message, line, column) ⇒ Object
-
#initialize ⇒ Handler
constructor
A new instance of Handler.
- #start_element(name) ⇒ Object
- #text(value) ⇒ Object
Constructor Details
#initialize ⇒ Handler
Returns a new instance of Handler.
35 36 37 |
# File 'lib/rfm/xml_mini/ox_sax.rb', line 35 def initialize() @stack = [] end |
Instance Attribute Details
#stack ⇒ Object
Returns the value of attribute stack.
33 34 35 |
# File 'lib/rfm/xml_mini/ox_sax.rb', line 33 def stack @stack end |
Instance Method Details
#append(key, value) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rfm/xml_mini/ox_sax.rb', line 74 def append(key, value) key = key.to_s h = @stack.last if h.has_key?(key) v = h[key] if v.is_a?(Array) v << value else h[key] = [v, value] end else h[key] = value end end |
#attr(name, value) ⇒ Object
43 44 45 46 47 |
# File 'lib/rfm/xml_mini/ox_sax.rb', line 43 def attr(name, value) unless @stack.empty? append(name, value) end end |
#cdata(value) ⇒ Object
53 54 55 |
# File 'lib/rfm/xml_mini/ox_sax.rb', line 53 def cdata(value) append('__content__', value) end |
#doc ⇒ Object
39 40 41 |
# File 'lib/rfm/xml_mini/ox_sax.rb', line 39 def doc @stack[0] end |
#end_element(name) ⇒ Object
66 67 68 |
# File 'lib/rfm/xml_mini/ox_sax.rb', line 66 def end_element(name) @stack.pop() end |
#error(message, line, column) ⇒ Object
70 71 72 |
# File 'lib/rfm/xml_mini/ox_sax.rb', line 70 def error(, line, column) raise Exception.new("#{} at #{line}:#{column}") end |
#start_element(name) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/rfm/xml_mini/ox_sax.rb', line 57 def start_element(name) if @stack.empty? @stack.push(Hash.new) end h = Hash.new append(name, h) @stack.push(h) end |
#text(value) ⇒ Object
49 50 51 |
# File 'lib/rfm/xml_mini/ox_sax.rb', line 49 def text(value) append('__content__', value) end |