class Thermostat

processes the current_value, wanted_value and the range and outputs if its cold, warm or pleasant

Attributes

airco[RW]
heating[RW]
range[RW]

Public Class Methods

new(current_value = 0, wanted_value = 0, range = 0) click to toggle source
# File lib/thermostat.rb, line 4
def initialize(current_value = 0, wanted_value = 0, range = 0)
  @current_value = current_value
  @wanted_value = wanted_value
  @range = range
end

Public Instance Methods

check() click to toggle source

checks whether the temperature is warm, cold or pleasant with the given current value, wanted value and range

# File lib/thermostat.rb, line 25
def check
  if @current_value < @wanted_value - @range
    warm
  elsif @current_value > @wanted_value + @range
    cold
  else
    pleasant
  end
end
cold() click to toggle source

low temperature results into cold which results back into an active airconditioning and an inactive heater

# File lib/thermostat.rb, line 10
def cold
  @airco = true
  @heating = false
end
pleasant() click to toggle source

pleasant temperature results into pleasant which results back into an inactive airconditioning and an inactive heater

# File lib/thermostat.rb, line 20
def pleasant
  @airco = false
  @heating = false
end
warm() click to toggle source

warm temperature results into warm which results back into an inactive airconditioning and an active heater

# File lib/thermostat.rb, line 15
def warm
  @airco = false
  @heating = true
end