Class: Thermostat
- Inherits:
-
Object
- Object
- Thermostat
- Defined in:
- lib/thermostat.rb
Overview
Determines if the heating should be turned on
Instance Attribute Summary collapse
-
#airco ⇒ Object
Returns the value of attribute airco.
-
#current_value ⇒ Object
Returns the value of attribute current_value.
-
#heating ⇒ Object
Returns the value of attribute heating.
-
#range ⇒ Object
Returns the value of attribute range.
-
#wanted_value ⇒ Object
Returns the value of attribute wanted_value.
Instance Method Summary collapse
-
#initialize(args) ⇒ Thermostat
constructor
Initializes the thermostat with wanted value, range and unit.
-
#return_airco ⇒ boolean
Return if airco should be turned on.
-
#return_heating ⇒ boolean
Return if heating should be turned on.
-
#update_current(current_value) ⇒ Object
Update the current value with given value.
-
#update_range(range) ⇒ Object
Update the range.
-
#update_thermo ⇒ String
Give return if the airco or heater should be turned on.
-
#update_wanted(wanted_value) ⇒ Object
Update the wanted value with given value.
Constructor Details
#initialize(args) ⇒ Thermostat
Initializes the thermostat with wanted value, range and unit
15 16 17 18 |
# File 'lib/thermostat.rb', line 15 def initialize(args) @wanted_value = args[:wanted_value] @range = args[:range] end |
Instance Attribute Details
#airco ⇒ Object
Returns the value of attribute airco.
9 10 11 |
# File 'lib/thermostat.rb', line 9 def airco @airco end |
#current_value ⇒ Object
Returns the value of attribute current_value.
8 9 10 |
# File 'lib/thermostat.rb', line 8 def current_value @current_value end |
#heating ⇒ Object
Returns the value of attribute heating.
9 10 11 |
# File 'lib/thermostat.rb', line 9 def heating @heating end |
#range ⇒ Object
Returns the value of attribute range.
8 9 10 |
# File 'lib/thermostat.rb', line 8 def range @range end |
#wanted_value ⇒ Object
Returns the value of attribute wanted_value.
8 9 10 |
# File 'lib/thermostat.rb', line 8 def wanted_value @wanted_value end |
Instance Method Details
#return_airco ⇒ boolean
Return if airco should be turned on
46 47 48 |
# File 'lib/thermostat.rb', line 46 def return_airco current_value > (wanted_value + range) end |
#return_heating ⇒ boolean
Return if heating should be turned on
51 52 53 |
# File 'lib/thermostat.rb', line 51 def return_heating current_value < (wanted_value - range) end |
#update_current(current_value) ⇒ Object
Update the current value with given value
33 34 35 |
# File 'lib/thermostat.rb', line 33 def update_current(current_value) @current_value = current_value end |
#update_range(range) ⇒ Object
Update the range
21 22 23 |
# File 'lib/thermostat.rb', line 21 def update_range(range) @range = range end |
#update_thermo ⇒ String
Give return if the airco or heater should be turned on
39 40 41 42 43 |
# File 'lib/thermostat.rb', line 39 def update_thermo airco = return_airco heating = return_heating "{\"cooling\":#{airco},\"heating\":#{heating}}" end |
#update_wanted(wanted_value) ⇒ Object
Update the wanted value with given value
27 28 29 |
# File 'lib/thermostat.rb', line 27 def update_wanted(wanted_value) @wanted_value = wanted_value end |