Class: Thermostat
- Inherits:
-
Object
- Object
- Thermostat
- Defined in:
- lib/thermostat.rb
Instance Attribute Summary collapse
-
#airco ⇒ Object
readonly
The status of the airco.
-
#heater ⇒ Object
readonly
The status of the heater.
-
#range ⇒ Double
The lower and upper margin around the wanted temperature.
-
#temp_curr ⇒ Double
Sets the current temperature.
-
#temp_wanted ⇒ Double
The wanted temperature.
Instance Method Summary collapse
-
#check_temp ⇒ Object
The [check_temp] method updates the airco and heater based on temp_curr.
-
#initialize(args) ⇒ Thermostat
constructor
The [initialize] method creates a Thermostat.
Constructor Details
#initialize(args) ⇒ Thermostat
The [initialize] method creates a Thermostat
19 20 21 22 23 24 25 |
# File 'lib/thermostat.rb', line 19 def initialize(args) @range = args.fetch(:range, 1.0) @temp_wanted = args.fetch(:temp_wanted, 20.0) @temp_curr = args.fetch(:temp_curr, 20.0) @airco = false @heater = false end |
Instance Attribute Details
#airco ⇒ Object (readonly)
Returns the status of the airco.
10 11 12 |
# File 'lib/thermostat.rb', line 10 def airco @airco end |
#heater ⇒ Object (readonly)
Returns the status of the heater.
12 13 14 |
# File 'lib/thermostat.rb', line 12 def heater @heater end |
#range ⇒ Double
Returns the lower and upper margin around the wanted temperature.
8 9 10 |
# File 'lib/thermostat.rb', line 8 def range @range end |
#temp_curr ⇒ Double
Sets the current temperature
4 5 6 |
# File 'lib/thermostat.rb', line 4 def temp_curr @temp_curr end |
#temp_wanted ⇒ Double
Returns the wanted temperature.
6 7 8 |
# File 'lib/thermostat.rb', line 6 def temp_wanted @temp_wanted end |
Instance Method Details
#check_temp ⇒ Object
The [check_temp] method updates the airco and heater based on temp_curr
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/thermostat.rb', line 28 def check_temp if @temp_curr > (@temp_wanted + @range / 2) @airco = true @heater = false elsif @temp_curr < (@temp_wanted - @range / 2) @airco = false @heater = true else @airco = false @heater = false end end |