Module: Factree

Extended by:
DSL
Defined in:
lib/factree.rb,
lib/factree/path.rb,
lib/factree/version.rb,
lib/factree/pathfinder.rb,
lib/factree/fact_source.rb

Defined Under Namespace

Modules: Aggregate, DSL, FactSource, Pathfinder Classes: Conclusion, Facts, FactsSpy, Path

Constant Summary collapse

NoConclusionError =

Raised when attempting to get a conclusion from an incomplete path

Class.new(StandardError)
VERSION =
"0.5.1"
InvalidConclusionError =

Raised when a decision proc fails to return a Conclusion as expected

Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.conclusion(value = nil) ⇒ Conclusion Originally defined in module DSL

Creates a Conclusion to return from a decision proc.

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

Parameters:

  • value (Object) (defaults to: nil)

    Any value, including nil

Returns:

.decide_between_alternatives(facts, *decide_procs) ⇒ Decision Originally defined in module DSL

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.

Parameters:

  • facts (Facts)

    The facts to pass through to the decision procs.

  • decide_procs (Array<#call>)

    A decision proc followed by alternative procs.

Returns:

  • (Decision)

    A decision tree that checks the alternatives in order to reach a conclusion.

.find_path(**facts, &decide) ⇒ Path Originally defined in module DSL

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.

Parameters:

  • facts (Hash)

    The set of facts used to make decisions

  • decide (Proc)

    The decision proc. Takes a set of Facts and returns a Conclusion.

Returns:

  • (Path)

    Information about the path followed through the tree