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

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

Overview

Provides hash-based grouping.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cog

#each, #to_dot, #to_relation

Constructor Details

#initialize(operand, attributes, as, allbut) ⇒ Hash

Creates a Group::Hash instance



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

def initialize(operand, attributes, as, allbut)
  @operand = operand
  @attributes = attributes
  @as = as
  @allbut = allbut
end

Instance Attribute Details

#allbutBoolean (readonly)

Returns Group all but specified attributes?.

Returns:

  • (Boolean)

    Group all but specified attributes?



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

def allbut
  @allbut
end

#asAttrName (readonly)

Returns Name of the new attribute.

Returns:

  • (AttrName)

    Name of the new attribute



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

def as
  @as
end

#attributesAttrList (readonly)

Returns Attributes to group.

Returns:

  • (AttrList)

    Attributes to group



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

def attributes
  @attributes
end

#operandEnumerable (readonly)

Returns The operand.

Returns:

  • (Enumerable)

    The operand



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

def operand
  @operand
end

Instance Method Details

#_each(&block) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/alf-engine/alf/engine/group/hash.rb', line 30

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