Class: Alf::Engine::Group::Hash
- Inherits:
-
Object
- Object
- Alf::Engine::Group::Hash
- 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
-
#allbut ⇒ Boolean
readonly
Group all but specified attributes?.
-
#as ⇒ AttrName
readonly
Name of the new attribute.
-
#attributes ⇒ AttrList
readonly
Attributes to group.
-
#operand ⇒ Enumerable
readonly
The operand.
Attributes included from Compiler::Cog
Instance Method Summary collapse
- #_each(&block) ⇒ Object
- #arguments ⇒ Object
-
#initialize(operand, attributes, as, allbut, expr = nil, compiler = nil) ⇒ Hash
constructor
Creates a Group::Hash instance.
- #options ⇒ Object
Methods included from Cog
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
#allbut ⇒ Boolean (readonly)
Returns Group all but specified attributes?.
20 21 22 |
# File 'lib/alf/engine/group/hash.rb', line 20 def allbut @allbut end |
#as ⇒ AttrName (readonly)
Returns Name of the new attribute.
17 18 19 |
# File 'lib/alf/engine/group/hash.rb', line 17 def as @as end |
#attributes ⇒ AttrList (readonly)
Returns Attributes to group.
14 15 16 |
# File 'lib/alf/engine/group/hash.rb', line 14 def attributes @attributes end |
#operand ⇒ Enumerable (readonly)
Returns The operand.
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 |
#arguments ⇒ Object
41 42 43 |
# File 'lib/alf/engine/group/hash.rb', line 41 def arguments [ attributes, as ] end |
#options ⇒ Object
45 46 47 |
# File 'lib/alf/engine/group/hash.rb', line 45 def {allbut: allbut} end |