Class: Factbase::As

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

Overview

and assigns values to a specific attribute of a fact.

Instance Method Summary collapse

Methods included from TermShared

#to_s

Constructor Details

#initialize(operands) ⇒ As

Constructor.



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

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

Instance Method Details

#evaluate(fact, maps, fb) ⇒ Boolean

Evaluate term on a fact.



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

def evaluate(fact, maps, fb)
  assert_args(2)
  a = @operands[0]
  raise "A symbol is expected as first argument of 'as'" unless a.is_a?(Symbol)
  vv = _values(1, fact, maps, fb)
  vv&.each { |v| fact.send(:"#{a}=", v) }
  true
end