Skip to content

Commit

Permalink
Merge e7706cf into 9e4669e
Browse files Browse the repository at this point in the history
  • Loading branch information
seban committed Jan 2, 2014
2 parents 9e4669e + e7706cf commit 0767801
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/gyoku/array.rb
Expand Up @@ -6,6 +6,8 @@
module Gyoku
class Array

NESTED_ELEMENT_NAME = "element"

# Translates a given +array+ to XML. Accepts the XML +key+ to add the elements to,
# whether to +escape_xml+ and an optional Hash of +attributes+.
def self.to_xml(array, key, escape_xml = true, attributes = {}, options = {})
Expand All @@ -17,6 +19,7 @@ def self.to_xml(array, key, escape_xml = true, attributes = {}, options = {})
else
case item
when ::Hash then xml.tag!(key, attrs) { xml << Hash.to_xml(item, options) }
when ::Array then xml.tag!(key, attrs) { xml << Array.to_xml(item, NESTED_ELEMENT_NAME) }
when NilClass then xml.tag!(key, "xsi:nil" => "true")
else xml.tag!(key, attrs) { xml << XMLValue.create(item, escape_xml) }
end
Expand Down
7 changes: 7 additions & 0 deletions spec/gyoku/array_spec.rb
Expand Up @@ -51,6 +51,13 @@

to_xml(array, "value", :escape_xml, :id => [1, 2]).should == result
end

it "handles nested Arrays" do
array = [["one", "two"]]
result = "<value><element>one</element><element>two</element></value>"

to_xml(array, "value").should == result
end
end

def to_xml(*args)
Expand Down

0 comments on commit 0767801

Please sign in to comment.