Class: Factbase::Empty

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

Overview

The ‘empty’ term checks for emptiness in the results of a query evaluation.

Instance Method Summary collapse

Methods included from TermShared

#to_s

Constructor Details

#initialize(operands) ⇒ Empty

Constructor.

Parameters:

  • operands (Array)

    Operands



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

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

Instance Method Details

#evaluate(fact, maps, fb) ⇒ Boolean

Evaluate term on a fact.

Parameters:

Returns:

  • (Boolean)

    The result of the emptiness check



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/factbase/terms/empty.rb', line 23

def evaluate(fact, maps, fb)
  assert_args(1)
  term = @operands[0]
  unless term.is_a?(Factbase::Term) || term.is_a?(Factbase::TermBase)
    raise "A term is expected, but '#{term}' provided"
  end
  # rubocop:disable Lint/UnreachableLoop
  fb.query(term, maps).each(fb, fact) do
    return false
  end
  # rubocop:enable Lint/UnreachableLoop
  true
end