hashtoxml 0.0.2 → 0.0.3
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/hashtoxml.rb +2 -26
- data/lib/hashtoxml.rb +1 -1
- metadata +1 -1
data/lib/hashtoxml/hashtoxml.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module HashToXml
|
2
2
|
require 'rexml/document'
|
3
3
|
require 'rubygems'
|
4
|
-
require 'merb-core/vendor/facets/inflect.rb' if not 'string'.respond_to? :plural
|
5
4
|
|
6
5
|
def to_xml(options = {})
|
7
6
|
options[:root_name] ||= 'root'
|
@@ -18,30 +17,7 @@ module HashToXml
|
|
18
17
|
end
|
19
18
|
|
20
19
|
protected
|
21
|
-
def
|
22
|
-
|
23
|
-
if not doc
|
24
|
-
doc = REXML::Document.new
|
25
|
-
root = doc.add_element(options[:root_name] )
|
26
|
-
root.attributes["type"] = options[:root_type]
|
27
|
-
end
|
28
|
-
root = doc.root
|
29
|
-
|
30
|
-
self.each do |value|
|
31
|
-
element_name = elements_name.to_s.singular
|
32
|
-
element_type = HashToXml.data_type(value)
|
33
|
-
|
34
|
-
element_text = REXML::Text.new(value.to_s) unless value.nil?
|
35
|
-
|
36
|
-
node = root.add_element(element_name)
|
37
|
-
node.attributes["type"] = element_type
|
38
|
-
node << element_text
|
39
|
-
end
|
40
|
-
|
41
|
-
doc
|
42
|
-
end
|
43
|
-
|
44
|
-
def hash_to_xml_document(options={}, doc = nil)
|
20
|
+
def to_xml_document(options={}, doc = nil)
|
45
21
|
if not doc
|
46
22
|
doc = REXML::Document.new
|
47
23
|
root = doc.add_element(options[:root_name] )
|
@@ -66,7 +42,7 @@ module HashToXml
|
|
66
42
|
node << value.hash_to_xml_document(options, doc)
|
67
43
|
elsif value.is_a? Array
|
68
44
|
value.class.send(:include, HashToXml) if not value.respond_to? :to_xml
|
69
|
-
node = value.
|
45
|
+
node = value.to_xml_document(options, node)
|
70
46
|
else
|
71
47
|
node << element_text
|
72
48
|
end
|
data/lib/hashtoxml.rb
CHANGED