Class: Factbase::Zero

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

Overview

The ‘zero` term that evaluates whether any of the operand values is zero when applied to a fact.

Instance Method Summary collapse

Methods included from TermShared

#to_s

Constructor Details

#initialize(operands) ⇒ Zero

Constructor.

Parameters:

  • operands (Array)

    Operands



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

def initialize(operands)
  super()
  @operands = operands
end

Instance Method Details

#evaluate(fact, maps, fb) ⇒ Boolean

Evaluate term on a fact.

Parameters:

Returns:

  • (Boolean)

    True if any value is zero



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

def evaluate(fact, maps, fb)
  assert_args(1)
  vv = _values(0, fact, maps, fb)
  return false if vv.nil?
  vv.any? { |v| (v.is_a?(Integer) || v.is_a?(Float)) && v.zero? }
end