Class: Factbase::Or
Overview
The ‘or’ term that represents a logical OR operation between multiple operands.
Instance Method Summary collapse
-
#evaluate(fact, maps, fb) ⇒ Boolean
Evaluate term on a fact.
-
#initialize(operands) ⇒ Or
constructor
Constructor.
- #simplify ⇒ Object
Methods inherited from TermBase
Constructor Details
#initialize(operands) ⇒ Or
Constructor.
13 14 15 16 17 |
# File 'lib/factbase/terms/or.rb', line 13 def initialize(operands) super() @operands = operands @op = :or end |
Instance Method Details
#evaluate(fact, maps, fb) ⇒ Boolean
Evaluate term on a fact.
23 24 25 26 27 28 |
# File 'lib/factbase/terms/or.rb', line 23 def evaluate(fact, maps, fb) (0..(@operands.size - 1)).each do |i| return true if Factbase::Boolean.new(_values(i, fact, maps, fb), @operands[i]).bool? end false end |
#simplify ⇒ Object
30 31 32 33 34 |
# File 'lib/factbase/terms/or.rb', line 30 def simplify unique = Factbase::Simplified.new(@operands).unique return unique[0] if unique.size == 1 Factbase::Term.new(@op, unique) end |