Skip to content
This repository has been archived by the owner on Apr 4, 2018. It is now read-only.

Commit

Permalink
Start walking the graph based on inputs.
Browse files Browse the repository at this point in the history
  • Loading branch information
threedaymonk committed Mar 22, 2012
1 parent 06a6dc4 commit 7239770
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/sibyl/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ def validate!
raise InvalidGraph.new(e)
end

def at(inputs)
step = @first_step
context = OpenStruct.new
inputs.each do |input|
result = step.compute(input, context)
step = @steps_by_name[result]
end
step
end

def l10n_keys
@steps.inject([]) { |keys, step|
keys + step.l10n_keys
Expand Down
18 changes: 18 additions & 0 deletions test/graph_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,22 @@ def graph(source)

assert_equal expected, g.metadata
end

it "should walk the nodes according to inputs" do
g = graph(%{
step multiple "Yes or no?"
option yes -> "How old are you?"
option no -> "Whatever"
step number "How old are you?"
go ->
if { input > 18 } -> "Adult"
otherwise -> "Child"
outcome "Whatever"
outcome "Adult"
outcome "Child"
})

assert_equal "How old are you?", g.at(["yes"]).name
assert_equal "Adult", g.at(["yes", 19]).name
end
end

0 comments on commit 7239770

Please sign in to comment.