Class: DeviceControl::Heater

Inherits:
Device
  • Object
show all
Defined in:
lib/device_control.rb

Overview

Alright, fine, let’s make a Heater Input is the control knob (turned far enough to on, else off) Output is watts

Direct Known Subclasses

Cooler

Constant Summary collapse

EFFICIENCY =

convert electricity into thermal output

0.999

Instance Attribute Summary collapse

Attributes inherited from Device

#knob

Instance Method Summary collapse

Methods inherited from Device

#input=

Methods included from Updateable

#update

Constructor Details

#initialize(watts, threshold: 0) ⇒ Heater

Returns a new instance of Heater.



58
59
60
61
62
# File 'lib/device_control.rb', line 58

def initialize(watts, threshold: 0)
  super()
  @watts = watts
  @threshold = threshold
end

Instance Attribute Details

#wattsObject (readonly)

Returns the value of attribute watts.



56
57
58
# File 'lib/device_control.rb', line 56

def watts
  @watts
end

Instance Method Details

#outputObject

output is all or none



65
66
67
# File 'lib/device_control.rb', line 65

def output
  @knob > @threshold ? (@watts * self.class::EFFICIENCY) : 0
end

#to_sObject



69
70
71
72
# File 'lib/device_control.rb', line 69

def to_s
  format("Power: %d W\tKnob: %.1f\tThermal: %.1f W",
         @watts, @knob, self.output)
end