Class: ActiveSupport::XmlMini_OxSAX::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/rfm/xml_mini/ox_sax.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHandler

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

#stackObject

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

#docObject



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

Raises:

  • (Exception)


70
71
72
# File 'lib/rfm/xml_mini/ox_sax.rb', line 70

def error(message, line, column)
  raise Exception.new("#{message} 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