Class: Alf::Engine::Unwrap

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

Overview

Unwraps a tuple attribute

Constant Summary

Constants included from Cog

Cog::EMPTY_CHILDREN, Cog::EMPTY_OPTIONS

Instance Attribute Summary collapse

Attributes included from Compiler::Cog

#compiler, #expr

Instance Method Summary collapse

Methods included from Cog

#children, #each, #options, #to_s

Methods included from Compiler::Cog

#cog_orders, #orderedby?, #relation_type, #to_ascii_tree, #to_cog, #to_relation

Constructor Details

#initialize(operand, attribute, expr = nil, compiler = nil) ⇒ Unwrap

Creates a SetAttr instance


16
17
18
19
20
# File 'lib/alf/engine/unwrap.rb', line 16

def initialize(operand, attribute, expr = nil, compiler = nil)
  super(expr, compiler)
  @operand = operand
  @attribute = attribute
end

Instance Attribute Details

#attributeAttrName (readonly)

Returns Name of the attribute to unwrap

Returns:

  • (AttrName)

    Name of the attribute to unwrap


13
14
15
# File 'lib/alf/engine/unwrap.rb', line 13

def attribute
  @attribute
end

#operandEnumerable (readonly)

Returns The operand

Returns:

  • (Enumerable)

    The operand


10
11
12
# File 'lib/alf/engine/unwrap.rb', line 10

def operand
  @operand
end

Instance Method Details

#_eachObject


23
24
25
26
27
28
29
30
31
32
# File 'lib/alf/engine/unwrap.rb', line 23

def _each
  operand.each do |tuple|
    tuple   = tuple.dup
    tuple   = tuple.to_hash unless tuple.is_a?(Hash)
    wrapped = tuple.delete(@attribute) || {}
    wrapped = symbolize(wrapped)
    tuple.merge!(wrapped)
    yield tuple
  end
end

#argumentsObject


34
35
36
# File 'lib/alf/engine/unwrap.rb', line 34

def arguments
  [ attribute ]
end