Class: Factbase::Or

Inherits:
TermBase show all
Defined in:
lib/factbase/terms/or.rb

Overview

The ‘or’ term that represents a logical OR operation between multiple operands.

Instance Method Summary collapse

Methods inherited from TermBase

#to_s

Constructor Details

#initialize(operands) ⇒ Or

Constructor.

Parameters:

  • operands (Array)

    Operands



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.

Parameters:

Returns:

  • (Boolean)

    True if any operand evaluates to true, false otherwise



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

#simplifyObject



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