Class: Foundry::Parsers::XML

Inherits:
Object
  • Object
show all
Defined in:
lib/foundry/parsers/xml.rb

Instance Method Summary collapse

Instance Method Details

#parse(str) ⇒ Object

Raises:

  • (TypeError)


7
8
9
10
11
12
13
14
15
16
# File 'lib/foundry/parsers/xml.rb', line 7

def parse(str)
  raise TypeError if str.nil?
  root_node = REXML::Document.new(str).first
  raise ArgumentError unless root_node.name == 'config'
  result = {}
  root_node.children.each { |node| result[node.name] = node.text }
  inherit = root_node.attributes['inherit']
  result['inherit'] = inherit unless inherit.nil?
  result
end