hashtoxml 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/hashtoxml.rb CHANGED
@@ -7,7 +7,7 @@ unless defined? HashToXml
7
7
  module HashToXml
8
8
 
9
9
  # :stopdoc:
10
- VERSION = '0.0.4'
10
+ VERSION = '0.0.5'
11
11
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
12
12
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
13
13
  # :startdoc:
@@ -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
- options[:element_name] = element_name.singular
48
- node = value.to_xml_document(options, node)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashtoxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leon Bogaert