Class: Factbase::Nth
Overview
Retrieves the value of a specified key from the nth map.
Instance Method Summary collapse
-
#evaluate(_fact, maps, _fb) ⇒ Object
Evaluate term on a fact.
-
#initialize(operands) ⇒ Nth
constructor
Constructor.
Methods included from TermShared
Constructor Details
#initialize(operands) ⇒ Nth
Constructor.
12 13 14 15 16 |
# File 'lib/factbase/terms/nth.rb', line 12 def initialize(operands) super() @operands = operands @op = :nth end |
Instance Method Details
#evaluate(_fact, maps, _fb) ⇒ Object
Evaluate term on a fact.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/factbase/terms/nth.rb', line 23 def evaluate(_fact, maps, _fb) assert_args(2) pos = @operands[0] raise "An integer is expected, but #{pos} provided" unless pos.is_a?(Integer) k = @operands[1] raise "A symbol is expected, but #{k} provided" unless k.is_a?(Symbol) m = maps[pos] return nil if m.nil? m[k.to_s] end |