Class: Hue::CLI::Processors::LightStateAlias

Inherits:
Object
  • Object
show all
Defined in:
lib/hue/cli/processors/light_state_alias.rb

Constant Summary collapse

ALIAS_FILE_NAME =
'light_alias.yml'
ALIAS_FILE_PATHS =
[
  File.join(Hue::CLI::LOCATION, 'config'),  # Default
  '/etc/hue/',   # System
  '~/.hue-cli/', # User
]
@@alias_map =
Hash.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ LightStateAlias

Returns a new instance of LightStateAlias.



30
31
32
33
34
35
36
# File 'lib/hue/cli/processors/light_state_alias.rb', line 30

def initialize(name)
  @name = name
  @state = @@alias_map[name.to_sym]
  if @state.nil?
    raise Error.new("Unknown light state: #{name}")
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



28
29
30
# File 'lib/hue/cli/processors/light_state_alias.rb', line 28

def name
  @name
end

#stateObject (readonly)

Returns the value of attribute state.



28
29
30
# File 'lib/hue/cli/processors/light_state_alias.rb', line 28

def state
  @state
end

Class Method Details

.read_alias_filesObject



13
14
15
16
17
18
19
20
21
# File 'lib/hue/cli/processors/light_state_alias.rb', line 13

def self.read_alias_files
  ALIAS_FILE_PATHS.each do |path|
    file_path = File.expand_path(File.join(path, ALIAS_FILE_NAME))
    yaml = YAML.load_file(file_path) rescue []
    yaml.each do |name, state|
      @@alias_map[name.to_sym] = state
    end
  end
end