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 included from TermShared
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 30 31 32 33 |
# File 'lib/factbase/terms/unique.rb', line 22 def evaluate(fact, maps, fb) @seen = Set.new if @seen.nil? raise "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) pass = true Enumerator.product(*vv).to_a.each do |t| pass = false if @seen.include?(t) @seen << t end pass end |