Class: Brewby::Application

Inherits:
Object
  • Object
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

#adapterObject

Returns the value of attribute adapter.



7
8
9
# File 'lib/brewby/application.rb', line 7

def adapter
  @adapter
end

#inputsObject (readonly)

Returns the value of attribute inputs.



6
7
8
# File 'lib/brewby/application.rb', line 6

def inputs
  @inputs
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/brewby/application.rb', line 7

def name
  @name
end

#outputsObject (readonly)

Returns the value of attribute outputs.



6
7
8
# File 'lib/brewby/application.rb', line 6

def outputs
  @outputs
end

#stepsObject (readonly)

Returns the value of attribute steps.



6
7
8
# File 'lib/brewby/application.rb', line 6

def steps
  @steps
end

Instance Method Details

#add_input(adapter, options = {}) ⇒ Object



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

#configure_inputsObject



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

#configure_outputsObject



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_stepObject



84
85
86
# File 'lib/brewby/application.rb', line 84

def current_step
  @current_step || @steps[0]
end

#load_recipe(file) ⇒ Object



56
57
58
# File 'lib/brewby/application.rb', line 56

def load_recipe file
  Brewby::StepLoader.new(self).load_file file
end

#ready_for_next_step?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/brewby/application.rb', line 71

def ready_for_next_step?
  @ready
end

#startObject



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

#tickObject



75
76
77
# File 'lib/brewby/application.rb', line 75

def tick
  current_step.step_iteration
end