class Thermostat

@author Jop Bouckaert Returns heating, cooling or normal state

Constants

DIVIDER

Attributes

cooling[RW]
current_value[RW]
heating[RW]
range[RW]
wanted_value[RW]

Public Class Methods

new(args) click to toggle source

@param [Hash] args the options to create a message with. @option args [Numeric] :current_value current value @option args [Numeric] :wanted_value wanted value @option args [Numeric] :range range

# File lib/thermostat.rb, line 15
def initialize(args)
  @current_value  = args[:current_value]  || 20
  @wanted_value   = args[:wanted_value]   || 30
  @range          = args[:range]          || 1
end

Public Instance Methods

state() click to toggle source

Sets the current state of the themostat

# File lib/thermostat.rb, line 22
def state
  @heating = @current_value < @wanted_value - @range / DIVIDER
  @cooling = @current_value > @wanted_value + @range / DIVIDER
end