Class: Led
- Inherits:
-
Object
- Object
- Led
- Defined in:
- lib/led.rb
Overview
Led type with full RGB hexadecimals output The Led class accepts any value and transform it to an hexadecimals RGB output.
Instance Method Summary collapse
-
#get_color ⇒ Number
RGB value in hexadecimals.
-
#initialize ⇒ Led
constructor
A new instance of Led.
-
#set_color(value) ⇒ Object
Set color in RGB hexadecimals.
-
#string ⇒ String
Return color in RGB hexadecimals in string format.
Constructor Details
#initialize ⇒ Led
Returns a new instance of Led.
5 6 7 8 |
# File 'lib/led.rb', line 5 def initialize @color = "000000" @zero = "00" end |
Instance Method Details
#get_color ⇒ Number
Returns RGB value in hexadecimals.
34 35 36 |
# File 'lib/led.rb', line 34 def get_color @color end |
#set_color(value) ⇒ Object
Set color in RGB hexadecimals
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/led.rb', line 12 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 ⇒ String
Return color in RGB hexadecimals in string format
29 30 31 |
# File 'lib/led.rb', line 29 def string "The LED is #{@color}" end |