hashtoxml 0.0.3 → 0.0.4
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/Rakefile +1 -1
- data/lib/hashtoxml/hashtoxml.rb +4 -1
- data/lib/hashtoxml.rb +1 -1
- metadata +12 -3
data/Rakefile
CHANGED
data/lib/hashtoxml/hashtoxml.rb
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
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? :singular
|
|
4
5
|
|
|
5
6
|
def to_xml(options = {})
|
|
6
7
|
options[:root_name] ||= 'root'
|
|
7
8
|
options[:include_type] ||= true
|
|
8
9
|
options[:indent] ||= 2
|
|
10
|
+
options[:element_name] ||= nil
|
|
9
11
|
|
|
10
12
|
if self.is_a? Array
|
|
11
13
|
options[:root_type] ||= 'array'
|
|
@@ -29,7 +31,7 @@ module HashToXml
|
|
|
29
31
|
element_type = HashToXml.data_type(value)
|
|
30
32
|
|
|
31
33
|
element_text = REXML::Text.new(value.to_s)
|
|
32
|
-
element_name = key.to_s
|
|
34
|
+
element_name = options[:element_name] || key.to_s
|
|
33
35
|
|
|
34
36
|
node = root.add_element(element_name)
|
|
35
37
|
node.attributes["type"] = element_type
|
|
@@ -42,6 +44,7 @@ module HashToXml
|
|
|
42
44
|
node << value.hash_to_xml_document(options, doc)
|
|
43
45
|
elsif value.is_a? Array
|
|
44
46
|
value.class.send(:include, HashToXml) if not value.respond_to? :to_xml
|
|
47
|
+
options[:element_name] = element_name.singular
|
|
45
48
|
node = value.to_xml_document(options, node)
|
|
46
49
|
else
|
|
47
50
|
node << element_text
|
data/lib/hashtoxml.rb
CHANGED
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
|
+
version: 0.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Leon Bogaert
|
|
@@ -11,8 +11,17 @@ cert_chain: []
|
|
|
11
11
|
|
|
12
12
|
date: 2008-09-07 00:00:00 +02:00
|
|
13
13
|
default_executable:
|
|
14
|
-
dependencies:
|
|
15
|
-
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: merb-core
|
|
17
|
+
type: :runtime
|
|
18
|
+
version_requirement:
|
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
20
|
+
requirements:
|
|
21
|
+
- - ">="
|
|
22
|
+
- !ruby/object:Gem::Version
|
|
23
|
+
version: 0.9.5
|
|
24
|
+
version:
|
|
16
25
|
description: FIXME (describe your package)
|
|
17
26
|
email: leon@tim-online.nl
|
|
18
27
|
executables:
|