module Factree::DSL

Readable shortcuts to common functions.

Public Instance Methods

conclusion(value=nil) click to toggle source

Creates a {Conclusion} to return from a decision proc.

The conclusion has an associated value (can be anything.)

@param [Object] value Any value, including nil @return [Conclusion]

# File lib/factree/dsl.rb, line 9
def conclusion(value=nil)
  Factree::Conclusion.new(value)
end
decide_between_alternatives(facts, *decide_procs) click to toggle source

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.

@param [Facts] facts The facts to pass through to the decision procs. @param [Array<#call>] decide_procs A decision proc followed by alternative procs. @return [Decision] A decision tree that checks the alternatives in order to reach a conclusion.

# 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) click to toggle source

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.

@param [Hash] facts The set of facts used to make decisions @param [Proc] decide The decision proc. Takes a set of {Facts} and returns a {Conclusion}. @return [Path] Information about the path followed through the tree

# File lib/factree/dsl.rb, line 26
def find_path(**facts, &decide)
  Factree::Pathfinder.find(facts, &decide)
end