Class: Brewby::Application
- Inherits:
-
Object
- Object
- Brewby::Application
show all
- Includes:
- Timed
- Defined in:
- lib/brewby/application.rb
Instance Attribute Summary collapse
Attributes included from Timed
#end_time, #start_time
Instance Method Summary
collapse
Methods included from Timed
#countdown_for, #elapsed, #ended?, #in_progress?, #start_timer, #started?, #stop_timer, #time_from_seconds, #timer_for
Constructor Details
#initialize(options = {}) ⇒ Application
Returns a new instance of Application.
11
12
13
14
15
16
17
18
|
# File 'lib/brewby/application.rb', line 11
def initialize options = {}
@options = options
@steps = []
@adapter = options[:adapter].to_sym
configure_inputs
configure_outputs
@ready = false
end
|
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
7
8
9
|
# File 'lib/brewby/application.rb', line 7
def adapter
@adapter
end
|
Returns the value of attribute inputs.
6
7
8
|
# File 'lib/brewby/application.rb', line 6
def inputs
@inputs
end
|
#name ⇒ Object
Returns the value of attribute name.
7
8
9
|
# File 'lib/brewby/application.rb', line 7
def name
@name
end
|
#outputs ⇒ Object
Returns the value of attribute outputs.
6
7
8
|
# File 'lib/brewby/application.rb', line 6
def outputs
@outputs
end
|
#steps ⇒ Object
Returns the value of attribute steps.
6
7
8
|
# File 'lib/brewby/application.rb', line 6
def steps
@steps
end
|
Instance Method Details
28
29
30
31
|
# File 'lib/brewby/application.rb', line 28
def add_input adapter, options = {}
sensor = Brewby::Inputs.adapter_class(adapter).new options
@inputs.push sensor
end
|
#add_output(adapter, options = {}) ⇒ Object
41
42
43
44
45
|
# File 'lib/brewby/application.rb', line 41
def add_output adapter, options = {}
output_adapter = Brewby::Outputs.adapter_class(adapter).new options
element = Brewby::HeatingElement.new output_adapter, pulse_range: options[:pulse_range], name: options[:name]
@outputs.push element
end
|
#add_step(step_type, options = {}) ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/brewby/application.rb', line 47
def add_step step_type, options = {}
case step_type
when :temp_control
default_options = { input: @inputs.first, output: @outputs.first }
step = Brewby::Steps::TempControl.new default_options.merge(options)
end
@steps.push step
end
|
20
21
22
23
24
25
26
|
# File 'lib/brewby/application.rb', line 20
def configure_inputs
@inputs = []
@options[:inputs].each do |input_options|
add_input @adapter, input_options
end
end
|
33
34
35
36
37
38
39
|
# File 'lib/brewby/application.rb', line 33
def configure_outputs
@outputs = []
@options[:outputs].each do |output_options|
add_output @adapter, output_options
end
end
|
#current_step ⇒ Object
84
85
86
|
# File 'lib/brewby/application.rb', line 84
def current_step
@current_step || @steps[0]
end
|
#load_recipe(file) ⇒ Object
#ready_for_next_step? ⇒ Boolean
71
72
73
|
# File 'lib/brewby/application.rb', line 71
def ready_for_next_step?
@ready
end
|
#start ⇒ Object
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/brewby/application.rb', line 60
def start
start_timer
@steps.each do |step|
start_step step
until ready_for_next_step?
tick
end
@ready = false
end
end
|
#start_step(step) ⇒ Object
79
80
81
82
|
# File 'lib/brewby/application.rb', line 79
def start_step step
@current_step = step
step.start_timer
end
|
#tick ⇒ Object
75
76
77
|
# File 'lib/brewby/application.rb', line 75
def tick
current_step.step_iteration
end
|