Class: Heater

Inherits:
Device 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.



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

#wattsObject (readonly)

Returns the value of attribute watts.



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

def watts
  @watts
end

Instance Method Details

#outputObject

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_sObject



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