Class: Brewby::HeatingElement

Inherits:
Object
  • Object
show all
Defined in:
lib/brewby/heating_element.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {}
  @pulse_range = options[:pulse_range] || 1000
  @on = false
  @pulse_range_end = (Time.now.to_i * 1000) + @pulse_range
  @adapter = adapter
  @pulse_width = 0
  @name = options[:name]
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



3
4
5
# File 'lib/brewby/heating_element.rb', line 3

def adapter
  @adapter
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/brewby/heating_element.rb', line 3

def name
  @name
end

#pulse_rangeObject

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_widthObject

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

Returns:

  • (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

Returns:

  • (Boolean)


53
54
55
# File 'lib/brewby/heating_element.rb', line 53

def on?
  @adapter.on?
end

#pulseObject



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_endObject



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

Returns:

  • (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

Returns:

  • (Boolean)


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

def pulse_within_width?
  @pulse_time <= pulse_end
end

#set_pulse_timeObject



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_rangeObject



37
38
39
# File 'lib/brewby/heating_element.rb', line 37

def update_pulse_range
  @pulse_range_end += @pulse_range
end