class Led

Led type with full RGB hexadecimals output The Led class accepts any value and transform it to an hexadecimals RGB output. @author Jasper Vercnocke <jasper.vercnocke@student.vives.be>

Public Class Methods

new() click to toggle source
# File lib/led.rb, line 5
def initialize
    @color = "000000"
    @zero = "00"
end

Public Instance Methods

get_color() click to toggle source

@return [Number] RGB value in hexadecimals

# File lib/led.rb, line 34
def get_color
    @color
end
set_color(value) click to toggle source

@param value [Number] color in decimals Set color in RGB hexadecimals

# 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() click to toggle source

Return color in RGB hexadecimals in string format @return [String] RGB value in hexadecimals

# File lib/led.rb, line 29
def string
    "The LED is #{@color}"
end