class Thermostat

Attributes

current_value[RW]
range[RW]
wanted_value[RW]

Public Class Methods

new(current_value = 19, wanted_value = 20, range = 1) click to toggle source

Initialize the thermostats current value, wanted value and range.

# File lib/thermostat.rb, line 4
def initialize(current_value = 19, wanted_value = 20, range = 1)
  @current_value = current_value
  @wanted_value = wanted_value
  @range = range
end

Public Instance Methods

set_airco() click to toggle source

Determines if it is necessary to put on the airco.

# File lib/thermostat.rb, line 19
def set_airco
  if @current_value > (@wanted_value + @range / 2)
    puts 'airco'
  elsif @current_value > (@wanted_value - @range / 2)
    puts 'Not to hot, not to cold ;)'
  end
end
set_heating() click to toggle source

Determines if it is necessary to put on the heating.

# File lib/thermostat.rb, line 28
def set_heating
  if @current_value < (@wanted_value - @range / 2)
    puts 'heating'
  elsif @current_value < (@wanted_value + @range / 2)
    puts 'Not to hot, not to cold ;)'
  end
end
update_current(current_value) click to toggle source
# File lib/thermostat.rb, line 14
def update_current(current_value)
  @current_value = current_value
end
wanted(wanted_value) click to toggle source
# File lib/thermostat.rb, line 10
def wanted(wanted_value)
  @wanted_value = wanted_value
end