hashtoxml 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hashtoxml.rb +1 -1
- data/lib/hashtoxml/hashtoxml.rb +14 -2
- metadata +1 -1
data/lib/hashtoxml.rb
CHANGED
data/lib/hashtoxml/hashtoxml.rb
CHANGED
@@ -28,9 +28,17 @@ module HashToXml
|
|
28
28
|
root = doc.root
|
29
29
|
|
30
30
|
self.each do |key, value|
|
31
|
+
#If it's an array, switch the values, 'cause in that case the value is
|
32
|
+
#more important and we don't care about the key!
|
33
|
+
if self.is_a? Array
|
34
|
+
value = key
|
35
|
+
key = nil
|
36
|
+
end
|
37
|
+
|
31
38
|
element_type = HashToXml.data_type(value)
|
32
39
|
|
33
40
|
element_text = REXML::Text.new(value.to_s)
|
41
|
+
#element_name = options[:element_name] || key.to_s
|
34
42
|
element_name = options[:element_name] || key.to_s
|
35
43
|
|
36
44
|
node = root.add_element(element_name)
|
@@ -43,9 +51,13 @@ module HashToXml
|
|
43
51
|
if value.is_a? Hash
|
44
52
|
node << value.hash_to_xml_document(options, doc)
|
45
53
|
elsif value.is_a? Array
|
54
|
+
#If there no_xml method, make it so!
|
46
55
|
value.class.send(:include, HashToXml) if not value.respond_to? :to_xml
|
47
|
-
|
48
|
-
|
56
|
+
|
57
|
+
#mutate the options only for this one
|
58
|
+
local_options = options.dup
|
59
|
+
local_options[:element_name] = element_name.singular
|
60
|
+
node = value.to_a.to_xml_document(local_options, node)
|
49
61
|
else
|
50
62
|
node << element_text
|
51
63
|
end
|