Class: Led
- Inherits:
-
Object
- Object
- Led
- Defined in:
- lib/led.rb
Instance Method Summary collapse
- #get_color ⇒ Object
-
#initialize ⇒ Led
constructor
A new instance of Led.
- #set_color(value) ⇒ Object
- #string ⇒ Object
Constructor Details
#initialize ⇒ Led
Returns a new instance of Led.
2 3 4 5 |
# File 'lib/led.rb', line 2 def initialize @color = "000000" @zero = "00" end |
Instance Method Details
#get_color ⇒ Object
27 28 29 |
# File 'lib/led.rb', line 27 def get_color @color end |
#set_color(value) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/led.rb', line 7 def set_color(value) if value < 0 calc = value.abs.to_s(16).rjust(2,'0') calc2 = (255-value.abs).abs.to_s(16).rjust(2,'0') @color = @zero+calc2+calc elsif value > 0 calc = value.abs.to_s(16).rjust(2,'0') calc2 = (255-value.abs).abs.to_s(16).rjust(2,'0') @color = calc + calc2 + @zero else @color = "00FF00" end end |
#string ⇒ Object
23 24 25 |
# File 'lib/led.rb', line 23 def string "The LED is #{@color}" end |