Class: Lamp

Inherits:
Object
  • Object
show all
Defined in:
lib/test_driven_lighting/lamp.rb

Constant Summary collapse

DEFAULT_COLORS_FILE =
"#{File.expand_path(File.dirname(__FILE__))}/data/default_colors.yml"
DEFAULT_COLORS =
YAML.load_file(DEFAULT_COLORS_FILE)['colors']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lamp_id) ⇒ Lamp

Returns a new instance of Lamp.



9
10
11
12
13
14
15
16
17
# File 'lib/test_driven_lighting/lamp.rb', line 9

def initialize(lamp_id)
  @is_on = true
  @id = lamp_id
  @hue = 0
  @saturation = 254
  @brightness = 254
  @transition_time = 0
  @colors = DEFAULT_COLORS
end

Instance Attribute Details

#brightnessObject

Returns the value of attribute brightness.



4
5
6
# File 'lib/test_driven_lighting/lamp.rb', line 4

def brightness
  @brightness
end

#colorsObject

Returns the value of attribute colors.



4
5
6
# File 'lib/test_driven_lighting/lamp.rb', line 4

def colors
  @colors
end

#hueObject

Returns the value of attribute hue.



4
5
6
# File 'lib/test_driven_lighting/lamp.rb', line 4

def hue
  @hue
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/test_driven_lighting/lamp.rb', line 4

def id
  @id
end

#is_onObject

Returns the value of attribute is_on.



4
5
6
# File 'lib/test_driven_lighting/lamp.rb', line 4

def is_on
  @is_on
end

#saturationObject

Returns the value of attribute saturation.



4
5
6
# File 'lib/test_driven_lighting/lamp.rb', line 4

def saturation
  @saturation
end

#transition_timeObject

Returns the value of attribute transition_time.



4
5
6
# File 'lib/test_driven_lighting/lamp.rb', line 4

def transition_time
  @transition_time
end

Instance Method Details

#color=(color) ⇒ Object



19
20
21
22
23
24
# File 'lib/test_driven_lighting/lamp.rb', line 19

def color= color
  raise "unknown color of #{color}" if @colors[color].nil?

  @hue = @colors[color]['hue']
  @saturation = @colors[color]['saturation']
end