Class: DeviceControl::Device

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

Overview

A Device is like a heater. It has a control knob, maybe on/off or perhaps a variable control. Its output (maybe on/off) depends on the control knob.

Direct Known Subclasses

Heater

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Updateable

#update

Constructor Details

#initializeDevice

Returns a new instance of Device.



31
32
33
# File 'lib/device_control.rb', line 31

def initialize
  @knob = 0.0
end

Instance Attribute Details

#knobObject (readonly)

Returns the value of attribute knob.



29
30
31
# File 'lib/device_control.rb', line 29

def knob
  @knob
end

Instance Method Details

#input=(val) ⇒ Object Also known as: knob=



35
36
37
# File 'lib/device_control.rb', line 35

def input=(val)
  @knob = val.to_f
end

#outputObject



40
41
42
# File 'lib/device_control.rb', line 40

def output
  @knob # do nothing by default
end

#to_sObject



44
45
46
# File 'lib/device_control.rb', line 44

def to_s
  format("Knob: %.3f\tOutput: %.3f", @knob, self.output)
end