Class: Factbase::Join
Overview
The Factbase::Join class is a specialized term that performs join operations between facts based on specified attribute mappings.
Instance Method Summary collapse
-
#evaluate(fact, maps, fb) ⇒ Boolean
Evaluate term on a fact.
-
#initialize(operands) ⇒ Join
constructor
Constructor.
Methods included from TermShared
Constructor Details
#initialize(operands) ⇒ Join
Constructor.
13 14 15 16 |
# File 'lib/factbase/terms/join.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 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/factbase/terms/join.rb', line 23 def evaluate(fact, maps, fb) assert_args(2) jumps = @operands[0] raise "A string is expected as first argument of 'join'" unless jumps.is_a?(String) jumps = jumps.split(',') .map(&:strip) .map { |j| j.split('<=').map(&:strip) } .map { |j| j.size == 1 ? [j[0], j[0]] : j } term = @operands[1] raise "A term is expected, but '#{term}' provided" unless term.is_a?(Factbase::Term) subset = fb.query(term, maps).each(fb, fact).to_a subset.each do |s| jumps.each do |to, from| s[from]&.each do |v| fact.send(:"#{to}=", v) end end end true end |