class Thermostat

Attributes

airco[RW]
current_value[RW]
heating[RW]
range[RW]
wanted_value[RW]

Public Class Methods

new(current_value = 0.0, wanted_value = 0.0, range = 0.0) click to toggle source

The initialize method makes a thermostat @param [Double] Json object that contains following values

* :current_value [Double] The temperature in the room
* :wanted_value [Double] The temperature that is wanted in the room
* :range [Double]The upper and under margin of the temperature
# File lib/thermostat.rb, line 8
def initialize(current_value = 0.0, wanted_value = 0.0, range = 0.0)
  @current_value = current_value
  @wanted_value = wanted_value
  @range = range / 2
end

Public Instance Methods

check() click to toggle source

This method wil check the input values: current value, wanted value and the range. When the current value is larger than the wanted value (plus the range), the cool method is being called. If the current value is smaller than the wanted value (minus the range), the heat method is being called. Otherwise the thermostat is putted off. @return [String] the thermostat status

# File lib/thermostat.rb, line 43
def check
  if @current_value > (@wanted_value + @range)
    cool
    puts 'Turning on airco.'
  elsif @current_value < (@wanted_value - @range)
    heat
    puts 'Turning on heating.'
  else
    off
    puts 'Temperature has been reached.'
  end
end
cool() click to toggle source

Cool method will set the airco on and heating off when temperature is above the wanted value

# File lib/thermostat.rb, line 23
def cool
  @heating = false
  @airco = true
end
heat() click to toggle source

Heat method will set the heating on and airco off when temperature is bellow the wanted value

# File lib/thermostat.rb, line 16
def heat
  @heating = true
  @airco = false
end
off() click to toggle source

The off method will turn off the heating and airco

# File lib/thermostat.rb, line 30
def off
  @heating = false
  @airco = false
end
put_temperature(temperature) click to toggle source

The put_temperature methode will get the temperature from the input values

# File lib/thermostat.rb, line 58
def put_temperature(temperature)
  @current_value = temperature
end