smacks-apricoteatsgorilla 0.3.91 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -229,23 +229,23 @@ class ApricotEatsGorilla
229
229
  # * +item+ - A Hash value to translate into an XML String.
230
230
  def nested_data_to_xml(name, item)
231
231
  case item
232
- when String, Symbol
233
- tag(name) { item.to_s }
234
232
  when Array
235
233
  item.map { |subitem| nested_data_to_xml(name, subitem) }.join
236
234
  when Hash
237
235
  tag(name) do
238
236
  opt_order(item).map { |tag, value|
239
237
  case value
240
- when String, Symbol
241
- tag(tag) { value.to_s }
242
238
  when Array
243
239
  value.map { |subitem| nested_data_to_xml(tag, subitem) }.join
244
240
  when Hash
245
241
  nested_data_to_xml(tag, value)
242
+ else
243
+ tag(tag) { value.to_s } if item.respond_to? :to_s
246
244
  end
247
245
  }.join
248
246
  end
247
+ else
248
+ tag(name) { item.to_s } if item.respond_to? :to_s
249
249
  end
250
250
  end
251
251
 
@@ -293,7 +293,7 @@ class ApricotEatsGorilla
293
293
  # Returns a sorted version of a given +hash+ if :sort_keys was enabled.
294
294
  def opt_order(hash)
295
295
  return hash unless sort_keys
296
- hash.sort_by { |kv| kv.first }
296
+ hash.keys.sort_by { |s| s.to_s }.map { |key| [key, hash[key]] }
297
297
  end
298
298
 
299
299
  end
@@ -86,6 +86,23 @@ class HashToXmlTest < Test::Unit::TestCase
86
86
  end
87
87
  end
88
88
  end
89
+
90
+ context "with a Hash different types of values" do
91
+ should "convert values responding to 'to_s' to Strings" do
92
+ date_time = DateTime.now
93
+ hash = { :apricot => {
94
+ :at => date_time,
95
+ :with => 100.01,
96
+ :when => nil,
97
+ :what => :gorillas
98
+ } }
99
+ expected = "<apricot><at>#{date_time}</at><what>gorillas</what>" <<
100
+ "<when></when><with>100.01</with></apricot>"
101
+
102
+ result = ApricotEatsGorilla.hash_to_xml(hash)
103
+ assert_equal expected, result
104
+ end
105
+ end
89
106
  end
90
107
 
91
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smacks-apricoteatsgorilla
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.91
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Harrington