class Factree::Path
{Path}s record useful information about an attempt to reach a {Conclusion} for a decision proc.
A path may or may not actually reach a conclusion. If it does, it will be {complete?} and return the {conclusion} value. If it doesn't, then you can get the names of all of the facts needed to get past the next decision step from {required_facts}.
Attributes
A list of the facts that were required to get this far, plus any facts needed to make further progress. If the path is not complete, then the facts in this list are sufficient to progress past this point.
@return [Array<Symbol>] A list of fact names in the order they're required in the tree
Public Class Methods
Want to create a path? Use {DSL.find_path} instead.
@api private
# File lib/factree/path.rb, line 12 def initialize(required_facts=[], conclusion=nil) @required_facts = required_facts.to_a.uniq @conclusion = conclusion freeze end
Public Instance Methods
# File lib/factree/path.rb, line 36 def ==(other) self.class == other.class && @required_facts == other.instance_variable_get(:@required_facts) && @conclusion == other.instance_variable_get(:@conclusion) end
A path is {complete?} if it has reached a conclusion.
# File lib/factree/path.rb, line 19 def complete? !@conclusion.nil? end
Returns the conclusion value if this path is complete.
# File lib/factree/path.rb, line 24 def conclusion # We don't want to return nil to indicate a missing conclusion, since that could confused for a nil conclusion with a nil value. raise Factree::NoConclusionError, "Attempted to get conclusion from incomplete path" unless complete? @conclusion.value end