Class: Alf::Engine::Group::Hash

Inherits:
Object
  • Object
show all
Includes:
Cog, Alf::Engine::Group
Defined in:
lib/alf/engine/group/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, #each, #to_s

Methods included from Compiler::Cog

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

Constructor Details

#initialize(operand, attributes, as, allbut, expr = nil, compiler = nil) ⇒ Hash

Creates a Group::Hash instance


23
24
25
26
27
28
29
# File 'lib/alf/engine/group/hash.rb', line 23

def initialize(operand, attributes, as, allbut, expr = nil, compiler = nil)
  super(expr, compiler)
  @operand = operand
  @attributes = attributes
  @as = as
  @allbut = allbut
end

Instance Attribute Details

#allbutBoolean (readonly)


20
21
22
# File 'lib/alf/engine/group/hash.rb', line 20

def allbut
  @allbut
end

#asAttrName (readonly)


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

def as
  @as
end

#attributesAttrList (readonly)


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

def attributes
  @attributes
end

#operandEnumerable (readonly)


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

def operand
  @operand
end

Instance Method Details

#_each(&block) ⇒ Object


32
33
34
35
36
37
38
39
# File 'lib/alf/engine/group/hash.rb', line 32

def _each(&block)
  atr, alb = @attributes, @allbut
  index = Materialize::Hash.new(operand, atr, !alb, expr)
  index.each_pair do |k,v|
    grouped = Clip.new(v, atr, alb).to_relation
    yield k.merge(@as => grouped)
  end
end

#argumentsObject


41
42
43
# File 'lib/alf/engine/group/hash.rb', line 41

def arguments
  [ attributes, as ]
end

#optionsObject


45
46
47
# File 'lib/alf/engine/group/hash.rb', line 45

def options
  {allbut: allbut}
end