16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/secure_trading/util.rb', line 16
def to_xml(hash, options = {})
options[:indent] ||= 2
options = {:builder => Builder::XmlMarkup.new(:indent => options[:indent])}.merge(options)
attributes = options[:attributes] ||= {}
root_attributes = attributes[options[:root].to_s] || {}
options[:builder].__send__(:method_missing, options[:root].to_s, root_attributes) do
hash.each do |key, value|
case value
when ::Hash
to_xml(value, options.merge({ :root => key, :skip_instruct => true }))
else
if value.respond_to?(:to_hash)
value = value.to_hash
end
if value.is_a?(Hash)
Util.to_xml(value, options.merge({ :root => key, :skip_instruct => true }))
else
options[:builder].tag!(key.to_s, value)
end
end
end
end
end
|