diff --git a/lib/gyoku/array.rb b/lib/gyoku/array.rb index 8be6cc8..db8e695 100644 --- a/lib/gyoku/array.rb +++ b/lib/gyoku/array.rb @@ -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 = {}) @@ -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 diff --git a/spec/gyoku/array_spec.rb b/spec/gyoku/array_spec.rb index 1921dc0..e22292a 100644 --- a/spec/gyoku/array_spec.rb +++ b/spec/gyoku/array_spec.rb @@ -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 = "onetwo" + + to_xml(array, "value").should == result + end end def to_xml(*args)