Class: Brewby::HeatingElement
- Inherits:
-
Object
- Object
- Brewby::HeatingElement
- Defined in:
- lib/brewby/heating_element.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pulse_range ⇒ Object
Returns the value of attribute pulse_range.
-
#pulse_width ⇒ Object
Returns the value of attribute pulse_width.
Instance Method Summary collapse
-
#initialize(adapter, options = {}) ⇒ HeatingElement
constructor
A new instance of HeatingElement.
- #off! ⇒ Object
- #off? ⇒ Boolean
- #on! ⇒ Object
- #on? ⇒ Boolean
- #pulse ⇒ Object
- #pulse_end ⇒ Object
- #pulse_exceeds_range? ⇒ Boolean
- #pulse_within_width? ⇒ Boolean
- #set_pulse_time ⇒ Object
- #update_pulse_range ⇒ Object
Constructor Details
#initialize(adapter, options = {}) ⇒ HeatingElement
Returns a new instance of HeatingElement.
5 6 7 8 9 10 11 12 |
# File 'lib/brewby/heating_element.rb', line 5 def initialize adapter, = {} @pulse_range = [:pulse_range] || 1000 @on = false @pulse_range_end = (Time.now.to_i * 1000) + @pulse_range @adapter = adapter @pulse_width = 0 @name = [:name] end |
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
3 4 5 |
# File 'lib/brewby/heating_element.rb', line 3 def adapter @adapter end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/brewby/heating_element.rb', line 3 def name @name end |
#pulse_range ⇒ Object
Returns the value of attribute pulse_range.
3 4 5 |
# File 'lib/brewby/heating_element.rb', line 3 def pulse_range @pulse_range end |
#pulse_width ⇒ Object
Returns the value of attribute pulse_width.
3 4 5 |
# File 'lib/brewby/heating_element.rb', line 3 def pulse_width @pulse_width end |
Instance Method Details
#off! ⇒ Object
49 50 51 |
# File 'lib/brewby/heating_element.rb', line 49 def off! @adapter.off end |
#off? ⇒ Boolean
57 58 59 |
# File 'lib/brewby/heating_element.rb', line 57 def off? !on? end |
#on! ⇒ Object
45 46 47 |
# File 'lib/brewby/heating_element.rb', line 45 def on! @adapter.on end |
#on? ⇒ Boolean
53 54 55 |
# File 'lib/brewby/heating_element.rb', line 53 def on? @adapter.on? end |
#pulse ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/brewby/heating_element.rb', line 14 def pulse set_pulse_time update_pulse_range if pulse_exceeds_range? if pulse_within_width? on! else off! end end |
#pulse_end ⇒ Object
41 42 43 |
# File 'lib/brewby/heating_element.rb', line 41 def pulse_end @pulse_range_end - (@pulse_range - @pulse_width) end |
#pulse_exceeds_range? ⇒ Boolean
33 34 35 |
# File 'lib/brewby/heating_element.rb', line 33 def pulse_exceeds_range? @pulse_time > @pulse_range_end end |
#pulse_within_width? ⇒ Boolean
29 30 31 |
# File 'lib/brewby/heating_element.rb', line 29 def pulse_within_width? @pulse_time <= pulse_end end |
#set_pulse_time ⇒ Object
25 26 27 |
# File 'lib/brewby/heating_element.rb', line 25 def set_pulse_time @pulse_time = (Time.now.to_i * 1000) end |
#update_pulse_range ⇒ Object
37 38 39 |
# File 'lib/brewby/heating_element.rb', line 37 def update_pulse_range @pulse_range_end += @pulse_range end |