Class: Factbase::Size

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

Overview

Factbase::Size is a term that calculates the size of an operand when evaluated on a given fact.

Instance Method Summary collapse

Methods included from TermShared

#to_s

Constructor Details

#initialize(operands) ⇒ Size

Constructor.

Parameters:

  • operands (Array)

    Operands



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

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

Instance Method Details

#evaluate(fact, _maps, _fb) ⇒ Integer

Evaluate term on a fact.

Parameters:

Returns:

  • (Integer)

    Size of the operand



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

def evaluate(fact, _maps, _fb)
  assert_args(1)
  v = _by_symbol(0, fact)
  return 0 if v.nil?
  return 1 unless v.respond_to?(:to_a)
  v.size
end