Class: Alf::Engine::SetAttr
- Inherits:
-
Object
- Object
- Alf::Engine::SetAttr
- 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
-
#computation ⇒ TupleComputation
readonly
Computed attributes as a computation.
-
#operand ⇒ Enumerable
readonly
The operand.
Instance Method Summary collapse
- #_each ⇒ Object
-
#initialize(operand, computation) ⇒ SetAttr
constructor
Creates a SetAttr instance.
Methods included from Cog
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
#computation ⇒ TupleComputation (readonly)
Returns Computed attributes as a computation.
28 29 30 |
# File 'lib/alf-engine/alf/engine/set_attr.rb', line 28 def computation @computation end |
#operand ⇒ Enumerable (readonly)
Returns The operand.
25 26 27 |
# File 'lib/alf-engine/alf/engine/set_attr.rb', line 25 def operand @operand end |
Instance Method Details
#_each ⇒ Object
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 |