class Thermostat
Attributes
airco[RW]
current_value[RW]
heating[RW]
range[RW]
unit[RW]
want_value[RW]
Public Class Methods
new(want_value = 0, range = 0, unit = 'celsius', current_value = 0)
click to toggle source
# File lib/thermostat.rb, line 4 def initialize(want_value = 0, range = 0, unit = 'celsius', current_value = 0) @current_value = current_value @want_value = want_value @range = range / 2 @unit = unit end
Public Instance Methods
all_off()
click to toggle source
# File lib/thermostat.rb, line 47 def all_off @heating = false @airco = false puts 'Perfect temperature' end
celsius_to_fahrenheit()
click to toggle source
# File lib/thermostat.rb, line 15 def celsius_to_fahrenheit @current_value = (@current_value * 1.8) + 32 end
celsius_to_kelvin()
click to toggle source
# File lib/thermostat.rb, line 11 def celsius_to_kelvin @current_value += 273.15 end
check_cool()
click to toggle source
# File lib/thermostat.rb, line 111 def check_cool cool if @current_value > @want_value end
check_heat()
click to toggle source
# File lib/thermostat.rb, line 107 def check_heat heat if @current_value < @want_value end
check_if_unit_is_celsius_to_fahrenheit(sensor_unit)
click to toggle source
# File lib/thermostat.rb, line 94 def check_if_unit_is_celsius_to_fahrenheit(sensor_unit) celsius_to_fahrenheit if sensor_unit == 'celsius' end
check_if_unit_is_celsius_to_kelvin(sensor_unit)
click to toggle source
# File lib/thermostat.rb, line 82 def check_if_unit_is_celsius_to_kelvin(sensor_unit) celsius_to_kelvin if sensor_unit == 'celsius' end
check_if_unit_is_fahrenheit_to_kelvin(sensor_unit)
click to toggle source
# File lib/thermostat.rb, line 86 def check_if_unit_is_fahrenheit_to_kelvin(sensor_unit) fahrenheit_to_kelvin if sensor_unit == 'fahrenheit' end
check_if_unit_is_fahrnheit_to_celsius(sensor_unit)
click to toggle source
# File lib/thermostat.rb, line 74 def check_if_unit_is_fahrnheit_to_celsius(sensor_unit) fahrenheit_to_celsius if sensor_unit == 'fahrenheit' end
check_if_unit_is_kelvin_to_celsius(sensor_unit)
click to toggle source
# File lib/thermostat.rb, line 78 def check_if_unit_is_kelvin_to_celsius(sensor_unit) kelvin_to_celsius if sensor_unit == 'kelvin' end
check_if_unit_is_kelvin_to_fahrenheit(sensor_unit)
click to toggle source
# File lib/thermostat.rb, line 90 def check_if_unit_is_kelvin_to_fahrenheit(sensor_unit) kelvin_to_fahrenheit if sensor_unit == 'kelvin' end
check_if_unit_to_celsius(sensor_unit)
click to toggle source
# File lib/thermostat.rb, line 59 def check_if_unit_to_celsius(sensor_unit) check_if_unit_is_fahrnheit_to_celsius(sensor_unit) if @unit == 'celsius' check_if_unit_is_kelvin_to_celsius(sensor_unit) if @unit == 'celsius' end
check_if_unit_to_fahrenheit(sensor_unit)
click to toggle source
# File lib/thermostat.rb, line 69 def check_if_unit_to_fahrenheit(sensor_unit) check_if_unit_is_celsius_to_fahrenheit(sensor_unit) if @unit == 'fahrenheit' check_if_unit_is_kelvin_to_fahrenheit(sensor_unit) if @unit == 'fahrenheit' end
check_if_unit_to_kelvin(sensor_unit)
click to toggle source
# File lib/thermostat.rb, line 64 def check_if_unit_to_kelvin(sensor_unit) check_if_unit_is_fahrenheit_to_kelvin(sensor_unit) if @unit == 'kelvin' check_if_unit_is_celsius_to_kelvin(sensor_unit) if @unit == 'kelvin' end
check_unit(sensor_unit)
click to toggle source
# File lib/thermostat.rb, line 53 def check_unit(sensor_unit) check_if_unit_to_celsius(sensor_unit) check_if_unit_to_fahrenheit(sensor_unit) check_if_unit_to_kelvin(sensor_unit) end
cool()
click to toggle source
# File lib/thermostat.rb, line 41 def cool @heating = false @airco = true puts 'Airco will be turned on.' end
fahrenheit_to_celsius()
click to toggle source
# File lib/thermostat.rb, line 27 def fahrenheit_to_celsius @current_value = (@current_value - 32) / 1.8 end
fahrenheit_to_kelvin()
click to toggle source
# File lib/thermostat.rb, line 31 def fahrenheit_to_kelvin @current_value = ((@current_value - 32) / 1.8) + 273.15 end
heat()
click to toggle source
# File lib/thermostat.rb, line 35 def heat @heating = true @airco = false puts 'Heat will be turned on.' end
it_in_range()
click to toggle source
# File lib/thermostat.rb, line 98 def it_in_range if (@current_value - @want_value).abs > @range check_heat check_cool else all_off end end
kelvin_to_celsius()
click to toggle source
# File lib/thermostat.rb, line 19 def kelvin_to_celsius @current_value -= 273.15 end
kelvin_to_fahrenheit()
click to toggle source
# File lib/thermostat.rb, line 23 def kelvin_to_fahrenheit @current_value = (@current_value - 273.15 * 1.8) + 32 end
run(sensor_unit)
click to toggle source
# File lib/thermostat.rb, line 115 def run(sensor_unit) check_unit(sensor_unit) it_in_range end