Class: Factbase::And

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

Overview

The ‘and’ term that represents a logical AND operation between multiple operands.

Instance Method Summary collapse

Methods included from TermShared

#to_s

Constructor Details

#initialize(operands) ⇒ And

Constructor.

Parameters:

  • operands (Array)

    Operands



12
13
14
15
16
# File 'lib/factbase/terms/and.rb', line 12

def initialize(operands)
  super()
  @operands = operands
  @op = :and
end

Instance Method Details

#evaluate(fact, maps, fb) ⇒ Boolean

Evaluate term on a fact.

Parameters:

Returns:

  • (Boolean)

    True if all operands evaluate to true, false otherwise



22
23
24
25
26
27
# File 'lib/factbase/terms/and.rb', line 22

def evaluate(fact, maps, fb)
  (0..(@operands.size - 1)).each do |i|
    return false unless Factbase::Boolean.new(_values(i, fact, maps, fb), @operands[i]).bool?
  end
  true
end