Class: AppleVPP::AppleSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/apple_vpp/apple_serializer.rb

Class Method Summary collapse

Class Method Details

.to_ruby(apple_hash) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/apple_vpp/apple_serializer.rb', line 4

def self.to_ruby(apple_hash)
  if apple_hash.kind_of?( Array )
    return apple_hash.collect { |i| to_ruby i }
  end
  
  keys_with_hashes = apple_hash.select { | _k, v | v.kind_of?( Hash ) || v.kind_of?( Array )}

  if keys_with_hashes.count > 0
    keys_with_hashes.each { |k, v| apple_hash[k] = to_ruby v }
  end

  Hash[ apple_hash.map { | k, v | [ k.underscore.to_sym, v ] } ]
end