class Thermostat
Attributes
current[RW]
range[RW]
wanted[RW]
Public Class Methods
new(current, wanted = 20.0, range = 1.0)
click to toggle source
# File lib/thermostat.rb, line 6 def initialize(current, wanted = 20.0, range = 1.0) @current = current @wanted = wanted @range = range end
Public Instance Methods
cooling?()
click to toggle source
# File lib/thermostat.rb, line 16 def cooling? @wanted < (@current - @range / 2) end
heating?()
click to toggle source
# File lib/thermostat.rb, line 12 def heating? @wanted > (@current + @range / 2) end
state()
click to toggle source
# File lib/thermostat.rb, line 20 def state if heating? puts JSON.generate(cooling: false, heating: true) JSON.generate(cooling: false, heating: true) elsif cooling? puts JSON.generate(cooling: true, heating: false) JSON.generate(cooling: true, heating: false) else puts JSON.generate(cooling: false, heating: false) JSON.generate(cooling: false, heating: false) end end