Class: Alf::Engine::Image::Hash

Inherits:
Object
  • Object
show all
Includes:
Cog, Alf::Engine::Image
Defined in:
lib/alf/engine/image/hash.rb

Overview

Provides hash-based grouping.

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, #to_s

Methods included from Compiler::Cog

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

Constructor Details

#initialize(left, right, as, expr = nil, compiler = nil) ⇒ Hash

Creates a Image::Hash instance


20
21
22
23
24
25
# File 'lib/alf/engine/image/hash.rb', line 20

def initialize(left, right, as, expr = nil, compiler = nil)
  super(expr, compiler)
  @left = left
  @right = right
  @as = as
end

Instance Attribute Details

#asAttrName (readonly)

Returns Name of the new attribute

Returns:

  • (AttrName)

    Name of the new attribute


17
18
19
# File 'lib/alf/engine/image/hash.rb', line 17

def as
  @as
end

#leftEnumerable (readonly)

Returns The left operand

Returns:

  • (Enumerable)

    The left operand


11
12
13
# File 'lib/alf/engine/image/hash.rb', line 11

def left
  @left
end

#rightEnumerable (readonly)

Returns The right operand

Returns:

  • (Enumerable)

    The right operand


14
15
16
# File 'lib/alf/engine/image/hash.rb', line 14

def right
  @right
end

Instance Method Details

#_each(&block) ⇒ Object


33
34
35
36
37
38
39
40
41
42
# File 'lib/alf/engine/image/hash.rb', line 33

def _each(&block)
  key_attrs, type, images = nil, nil, nil
  left.each do |left_tuple|
    unless key_attrs
      key_attrs, type, images = build_index(left_tuple, right)
    end
    key = key_attrs.project_tuple(left_tuple)
    yield left_tuple.merge(@as => type.new(images[key]))
  end
end

#argumentsObject


48
49
50
# File 'lib/alf/engine/image/hash.rb', line 48

def arguments
  [ as ]
end

#each(&block) ⇒ Object


27
28
29
30
# File 'lib/alf/engine/image/hash.rb', line 27

def each(&block)
  return to_enum unless block
  dup._each(&block)
end

#operandsObject


44
45
46
# File 'lib/alf/engine/image/hash.rb', line 44

def operands
  [ left, right ]
end

#optionsObject


52
53
54
# File 'lib/alf/engine/image/hash.rb', line 52

def options
  {}
end