Skip to content

Commit

Permalink
Merge commit 'dc2ea2b59e5a3e30d5fff49baf52f8cf96d03890' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins committed Oct 14, 2015
2 parents f5dfc85 + dc2ea2b commit 2bb1110
Show file tree
Hide file tree
Showing 44 changed files with 722 additions and 161 deletions.
9 changes: 8 additions & 1 deletion lib/smart_answer/question/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ def initialize(flow, name, options = {}, &block)
super
end

def next_node(next_node = nil, &block)
def next_node(next_node = nil, permitted: [], &block)
if block_given?
unless permitted.any?
raise "You must specify the permitted next nodes"
end
@permitted_next_nodes += permitted
@default_next_node_function = block
elsif next_node
next_node_if(next_node)
Expand Down Expand Up @@ -44,6 +48,9 @@ def next_node_for(current_state, input)
next_node = next_node_from_function_chain(current_state, input) || next_node_from_default_function(current_state, input)
responses_and_input = current_state.responses + [input]
raise NextNodeUndefined.new("Next node undefined. Node: #{current_state.current_node}. Responses: #{responses_and_input}") unless next_node
unless @permitted_next_nodes.include?(next_node)
raise "Next node (#{next_node}) not in list of permitted next nodes (#{@permitted_next_nodes.to_sentence})"
end
next_node
end

Expand Down
20 changes: 18 additions & 2 deletions lib/smart_answer_flows/additional-commodity-code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ def define

save_input_as :starch_glucose_weight

next_node do |response|
permitted_next_nodes = [
:how_much_sucrose_1?,
:how_much_sucrose_2?,
:how_much_sucrose_3?,
:how_much_sucrose_4?
]

next_node(permitted: permitted_next_nodes) do |response|
case response.to_i
when 25
:how_much_sucrose_2?
Expand Down Expand Up @@ -90,7 +97,16 @@ def define

save_input_as :milk_fat_weight

next_node do |response|
permitted_next_nodes = [
:commodity_code_result,
:how_much_milk_protein_ab?,
:how_much_milk_protein_c?,
:how_much_milk_protein_d?,
:how_much_milk_protein_ef?,
:how_much_milk_protein_gh?
]

next_node(permitted: permitted_next_nodes) do |response|
case response.to_i
when 0, 1
:how_much_milk_protein_ab?
Expand Down
Loading

0 comments on commit 2bb1110

Please sign in to comment.