Skip to content

Commit c0256da

Browse files
committed
Arrays of strings are not translated #11
1 parent 525a6a2 commit c0256da

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/qbxml/hash.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ def self.hash_to_xml(hash, opts = {})
6060
when Hash
6161
self.hash_to_xml(val, opts.merge({root: key, skip_instruct: true}))
6262
when Array
63-
val.map { |i| self.hash_to_xml(i, opts.merge({root: key, skip_instruct: true})) }
63+
val.map { |i|
64+
if i.is_a?(String)
65+
next builder.tag!(key, i, {})
66+
end
67+
next self.hash_to_xml(i, opts.merge({root: key, skip_instruct: true}))
68+
}
6469
else
6570
builder.tag!(key, val, {})
6671
end

test/unit/hash_to_xml_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require 'minitest/autorun'
2+
require 'qbxml'
3+
4+
class VersionTest < Minitest::Test
5+
6+
def test_hash_to_xml
7+
assert_equal "<foo>\n <bar>baz</bar>\n</foo>\n", Qbxml::Hash.to_xml({:foo => {:bar => 'baz'}}, {skip_instruct: true})
8+
end
9+
10+
def test_array_of_strings
11+
assert_equal "<foo>\n <bar>baz</bar>\n <bar>guh</bar>\n</foo>\n", Qbxml::Hash.to_xml({:foo => {:bar => ['baz', 'guh']}}, {skip_instruct: true})
12+
end
13+
14+
end

0 commit comments

Comments
 (0)