Module: Swirl::Helpers::Compactor
- Included in:
- AWS
- Defined in:
- lib/swirl/helpers.rb
Class Method Summary collapse
Class Method Details
.compact(response) ⇒ Object
7 8 9 |
# File 'lib/swirl/helpers.rb', line 7 def compact(response) compact!(response.shift.last) end |
.compact!(value) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/swirl/helpers.rb', line 12 def compact!(value) case value when Hash # We don't need to stink'n xmlns! value.delete("xmlns") if value.has_key?("member") || value.has_key?("item") value = value["member"] || value["item"] if value == nil [] else value = compact!(value) # Can't use Array() here. :( value.is_a?(Array) ? value : [value] end else value.inject({}) do |m, (k, v)| m[k] = compact!(v) ; m end end when Array value.map {|v| compact!(v) } else value end end |