Module: Hue::TranslateKeys

Included in:
Group, Light, Scene
Defined in:
lib/hue/translate_keys.rb

Instance Method Summary collapse

Instance Method Details

#translate_keys(hash, map) ⇒ Object


3
4
5
6
7
8
9
10
11
# File 'lib/hue/translate_keys.rb', line 3

def translate_keys(hash, map)
  new_hash = {}
  hash.each do |key, value|
    new_key = map[key.to_sym]
    key = new_key if new_key
    new_hash[key] = value
  end
  new_hash
end

#unpack_hash(hash, map) ⇒ Object


13
14
15
16
17
18
19
# File 'lib/hue/translate_keys.rb', line 13

def unpack_hash(hash, map)
  map.each do |local_key, remote_key|
    value = hash[remote_key.to_s]
    next unless value
    instance_variable_set("@#{local_key}", value)
  end
end