Module: Factree::DSL
- Included in:
- Factree
- Defined in:
- lib/factree/dsl.rb
Overview
Readable shortcuts to common functions.
Instance Method Summary collapse
-
#conclusion(value = nil) ⇒ Conclusion
Creates a Conclusion to return from a decision proc.
-
#decide_between_alternatives(facts, *decide_procs) ⇒ Decision
A tool for composing lists of decision procs to be tried one after another until a conclusion is reached.
-
#find_path(**facts, &decide) ⇒ Path
Navigates as far as possible through a decision tree with the given set of facts.
Instance Method Details
#conclusion(value = nil) ⇒ Conclusion
Creates a Conclusion to return from a decision proc.
The conclusion has an associated value (can be anything.)
9 10 11 |
# File 'lib/factree/dsl.rb', line 9 def conclusion(value=nil) Factree::Conclusion.new(value) end |
#decide_between_alternatives(facts, *decide_procs) ⇒ Decision
A tool for composing lists of decision procs to be tried one after another until a conclusion is reached. When a proc returns nil instead of a Conclusion, the next proc in decide_procs is used instead.
If the last decision proc is reached and it returns nil, then this method returns nil.
37 38 39 |
# File 'lib/factree/dsl.rb', line 37 def decide_between_alternatives(facts, *decide_procs) Factree::Aggregate.alternatives(facts, *decide_procs) end |
#find_path(**facts, &decide) ⇒ Path
Navigates as far as possible through a decision tree with the given set of facts.
The path will stop when either
-
a conclusion is returned, or
-
there aren’t enough facts to make the decision.
Errors
If a decision function fails to return a Conclusion, an InvalidConclusionError will be raised.
26 27 28 |
# File 'lib/factree/dsl.rb', line 26 def find_path(**facts, &decide) Factree::Pathfinder.find(facts, &decide) end |