Class: Heater
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
Constant Summary collapse
- EFFICIENCY =
convert electricity into thermal output
0.999
Instance Attribute Summary collapse
-
#watts ⇒ Object
readonly
Returns the value of attribute watts.
Attributes inherited from Device
Instance Method Summary collapse
-
#initialize(watts, threshold: 0) ⇒ Heater
constructor
A new instance of Heater.
-
#output ⇒ Object
output is all or none.
- #to_s ⇒ Object
Methods inherited from Device
Methods included from Updateable
Constructor Details
#initialize(watts, threshold: 0) ⇒ Heater
Returns a new instance of Heater.
57 58 59 60 61 |
# File 'lib/device_control.rb', line 57 def initialize(watts, threshold: 0) super() @watts = watts @threshold = threshold end |
Instance Attribute Details
#watts ⇒ Object (readonly)
Returns the value of attribute watts.
55 56 57 |
# File 'lib/device_control.rb', line 55 def watts @watts end |
Instance Method Details
#output ⇒ Object
output is all or none
64 65 66 |
# File 'lib/device_control.rb', line 64 def output @knob > @threshold ? (@watts * self.class::EFFICIENCY) : 0 end |
#to_s ⇒ Object
68 69 70 71 |
# File 'lib/device_control.rb', line 68 def to_s format("Power: %d W\tKnob: %.1f\tThermal: %.1f W", @watts, @knob, self.output) end |