Class: Factbase::Unique
- Defined in:
- lib/factbase/terms/unique.rb
Overview
of terms based on provided operands and facts.
Instance Method Summary collapse
-
#evaluate(fact, maps, fb) ⇒ Boolean
Evaluate term on a fact.
-
#initialize(operands) ⇒ Unique
constructor
Constructor.
Methods inherited from TermBase
Constructor Details
#initialize(operands) ⇒ Unique
Constructor.
12 13 14 15 |
# File 'lib/factbase/terms/unique.rb', line 12 def initialize(operands) super() @operands = operands end |
Instance Method Details
#evaluate(fact, maps, fb) ⇒ Boolean
Evaluate term on a fact.
22 23 24 25 26 27 28 29 |
# File 'lib/factbase/terms/unique.rb', line 22 def evaluate(fact, maps, fb) @seen = Set.new if @seen.nil? raise(ArgumentError, "Too few operands for 'unique' (at least 1 expected)") if @operands.empty? vv = (0..(@operands.size - 1)).map { |i| _values(i, fact, maps, fb) } return false if vv.any?(nil) tuples = Enumerator.product(*vv).to_a tuples.none? { |t| @seen.include?(t) }.tap { tuples.each { |t| @seen << t } } end |