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 inherited from TermBase

#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
# File 'lib/factbase/terms/when.rb', line 23

def evaluate(fact, maps, fb)
  assert_args(2)
  return true unless @operands[0].evaluate(fact, maps, fb)
  @operands[1].evaluate(fact, maps, fb)
end