class Thermostat

Public Class Methods

new(currentTemp,range,wantedTemp,unit) click to toggle source
# File lib/Thermostat.rb, line 4
def initialize(currentTemp,range,wantedTemp,unit)
@currentTemp = currentTemp
@wantedTemp = wantedTemp
@range = range
@unit = unit
@heater = false
@airco = false
end

Public Instance Methods

output() click to toggle source
# File lib/Thermostat.rb, line 28
def output()
    if(@airco == false && @heater == false)
        puts "The current temperature is equal to the wanted temperature"
    elsif (@airco == false && @heater == true)
        puts "The heater is on, the Airco is off"
    elsif (@airco == true && @heater == false)
        puts "The heater is off, the Airco is on"
    end
end
outputJson() click to toggle source
# File lib/Thermostat.rb, line 38
def outputJson()
    my_object = { :heater => @heater, :airco => @airco }
    @outputJson = JSON.pretty_generate(my_object)
    puts @outputJson
end
regulate() click to toggle source
# File lib/Thermostat.rb, line 13
def regulate()
    c = Convert.new(@currentTemp,@range,@wantedTemp,@unit)
    c.convert_temp()
    if c.endtemp > (c.endWantedTemp + c.endrange)
        @airco = true 
        @heater = false 
    elsif c.endtemp < (c.endWantedTemp - c.endrange)
        @airco = false
        @heater = true
    else
        @airco = false
        @heater = false
    end
end