Class: Lamp
- Inherits:
-
Object
- Object
- Lamp
- 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
-
#brightness ⇒ Object
Returns the value of attribute brightness.
-
#colors ⇒ Object
Returns the value of attribute colors.
-
#hue ⇒ Object
Returns the value of attribute hue.
-
#id ⇒ Object
Returns the value of attribute id.
-
#is_on ⇒ Object
Returns the value of attribute is_on.
-
#saturation ⇒ Object
Returns the value of attribute saturation.
-
#transition_time ⇒ Object
Returns the value of attribute transition_time.
Instance Method Summary collapse
- #color=(color) ⇒ Object
-
#initialize(lamp_id) ⇒ Lamp
constructor
A new instance of Lamp.
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
#brightness ⇒ Object
Returns the value of attribute brightness.
4 5 6 |
# File 'lib/test_driven_lighting/lamp.rb', line 4 def brightness @brightness end |
#colors ⇒ Object
Returns the value of attribute colors.
4 5 6 |
# File 'lib/test_driven_lighting/lamp.rb', line 4 def colors @colors end |
#hue ⇒ Object
Returns the value of attribute hue.
4 5 6 |
# File 'lib/test_driven_lighting/lamp.rb', line 4 def hue @hue end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/test_driven_lighting/lamp.rb', line 4 def id @id end |
#is_on ⇒ Object
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 |
#saturation ⇒ Object
Returns the value of attribute saturation.
4 5 6 |
# File 'lib/test_driven_lighting/lamp.rb', line 4 def saturation @saturation end |
#transition_time ⇒ Object
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 |