Class: Factbase::When

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

Overview

It evaluates the operands based on a logical “when” operation.

Instance Method Summary collapse

Methods included from TermShared

#to_s

Constructor Details

#initialize(operands) ⇒ When

Constructor.

Parameters:

  • operands (Array)

    Operands



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

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

Instance Method Details

#evaluate(fact, maps, fb) ⇒ Boolean

Evaluate term on a fact.

Parameters:

Returns:

  • (Boolean)

    True if first operand is false OR both are true



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

def evaluate(fact, maps, fb)
  assert_args(2)
  a = @operands[0]
  b = @operands[1]
  !a.evaluate(fact, maps, fb) || (a.evaluate(fact, maps, fb) && b.evaluate(fact, maps, fb))
end