class Thermostat

Attributes

cooling[R]
heating[R]

Public Class Methods

new(args) click to toggle source
# File lib/thermostat.rb, line 4
def initialize(args)
  @current_value = args.fetch(:current_temperature, 20)
  @wanted_value = args.fetch(:wanted_temperature, 20)
  @range = args.fetch(:range, 1) / 2
end

Public Instance Methods

all_off() click to toggle source
# File lib/thermostat.rb, line 20
def all_off
  @heating = false
  @cooling = false
end
cool() click to toggle source
# File lib/thermostat.rb, line 15
def cool
  @heating = false
  @cooling = true
end
heat() click to toggle source
# File lib/thermostat.rb, line 10
def heat
  @heating = true
  @cooling = false
end
temp(new_temperature) click to toggle source
# File lib/thermostat.rb, line 25
def temp(new_temperature)
  @current_value = new_temperature
end
update() click to toggle source
# File lib/thermostat.rb, line 29
def update
  if @current_value < @wanted_value - @range
    heat
  elsif @current_value > @wanted_value + @range
    cool
  else
    all_off
  end
end