Module: Hue::Colors

Defined in:
lib/hue/colors.rb,
lib/hue/colors/xy.rb,
lib/hue/colors/rgb.rb,
lib/hue/colors/color.rb,
lib/hue/colors/hue_saturation.rb,
lib/hue/colors/color_temperature.rb

Defined Under Namespace

Classes: Color, ColorTemperature, HueSaturation, RGB, XY

Class Method Summary collapse

Class Method Details

.parse(*args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/hue/colors.rb', line 10

def self.parse(*args)
  case args.size
  when 1
    Colors::ColorTemperature.new(args.first)
  when 2
    a,b = args.first.to_f, args.last.to_f
    if a > 1.0
      Colors::HueSaturation.new(args.first, args.last)
    else
      Colors::XY.new(*args)
    end
  when 3
    Colors::RGB.new(*args)
  else
    raise Error.new("Unable to parse to color: #{args.inspect}")
  end
end

.parse_state(state) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/hue/colors.rb', line 28

def self.parse_state(state)
  case state['colormode']
  when 'ct'
    Colors::ColorTemperature.new(state['ct'])
  when 'xy'
    Colors::XY.new(*state['xy'])
  when 'hs'
    Colors::HueSaturation.new(state['hue'], state['sat'])
  else
    raise Error.new("Unknown or missing state: #{state.inspect}")
  end
end