Class: Factbase::First
Overview
The ‘first’ term is used to retrieve the value of a specified key from the first map in a set of maps.
Instance Method Summary collapse
-
#evaluate(_fact, maps, _fb) ⇒ Object
Evaluate term on a fact.
-
#initialize(operands) ⇒ First
constructor
Constructor.
Methods included from TermShared
Constructor Details
#initialize(operands) ⇒ First
Constructor.
11 12 13 14 15 |
# File 'lib/factbase/terms/first.rb', line 11 def initialize(operands) super() @operands = operands @op = :first end |
Instance Method Details
#evaluate(_fact, maps, _fb) ⇒ Object
Evaluate term on a fact.
22 23 24 25 26 27 28 29 |
# File 'lib/factbase/terms/first.rb', line 22 def evaluate(_fact, maps, _fb) assert_args(1) k = @operands[0] raise "A symbol is expected, but #{k} provided" unless k.is_a?(Symbol) first = maps[0] return nil if first.nil? first[k.to_s] end |