Class: Alf::Engine::SetAttr

Inherits:
Object
  • Object
show all
Includes:
Cog
Defined in:
lib/alf-engine/alf/engine/set_attr.rb

Overview

Set computed tuples attributes. This cog allows implementing both EXTEND and UPDATE relational operators.

Example:

rel = [
  {:name => "Jones", :city => "London"}
]
comp = TupleComputation[
  :city   => lambda{ city.upcase },
  :concat => lambda{ "#{name} #{city}" }
]
SetAttr.new(rel, comp).to_a
# => [
#      {:name => "Jones", :city => "LONDON", :concat => "Jones LONDON"}
#    ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cog

#each, #to_dot, #to_relation

Constructor Details

#initialize(operand, computation) ⇒ SetAttr

Creates a SetAttr instance



31
32
33
34
# File 'lib/alf-engine/alf/engine/set_attr.rb', line 31

def initialize(operand, computation)
  @operand = operand
  @computation = computation
end

Instance Attribute Details

#computationTupleComputation (readonly)

Returns Computed attributes as a computation.

Returns:

  • (TupleComputation)

    Computed attributes as a computation



28
29
30
# File 'lib/alf-engine/alf/engine/set_attr.rb', line 28

def computation
  @computation
end

#operandEnumerable (readonly)

Returns The operand.

Returns:

  • (Enumerable)

    The operand



25
26
27
# File 'lib/alf-engine/alf/engine/set_attr.rb', line 25

def operand
  @operand
end

Instance Method Details

#_eachObject



37
38
39
40
41
42
43
# File 'lib/alf-engine/alf/engine/set_attr.rb', line 37

def _each
  scope = tuple_scope
  operand.each do |tuple|
    computed = @computation.evaluate(scope.__set_tuple(tuple))
    yield tuple.merge(computed)
  end
end