Class: Alf::Engine::Autonum
- Inherits:
-
Object
- Object
- Alf::Engine::Autonum
- Includes:
- Cog
- Defined in:
- lib/alf/engine/autonum.rb
Overview
Autonumbers input tuples under a new as attribute. Autonumbering starts at 0.
Example:
operand = [
{:name => "Jones"},
{:name => "Smith"}
]
Autonum.new(operand, :id).to_a
# => [
# {:name => "Jones", :id => 0},
# {:name => "Smith", :id => 1}
# ]
Constant Summary
Constants included from Cog
Cog::EMPTY_CHILDREN, Cog::EMPTY_OPTIONS
Instance Attribute Summary collapse
-
#as ⇒ Symbol
readonly
Name of the autonum attribute.
-
#operand ⇒ Enumerable
readonly
The operand.
Attributes included from Compiler::Cog
Instance Method Summary collapse
- #_each ⇒ Object
- #arguments ⇒ Object
-
#initialize(operand, as, expr = nil, compiler = nil) ⇒ Autonum
constructor
Creates an Autonum instance.
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, as, expr = nil, compiler = nil) ⇒ Autonum
Creates an Autonum instance
29 30 31 32 33 |
# File 'lib/alf/engine/autonum.rb', line 29 def initialize(operand, as, expr = nil, compiler = nil) super(expr, compiler) @operand = operand @as = as end |
Instance Attribute Details
#as ⇒ Symbol (readonly)
26 27 28 |
# File 'lib/alf/engine/autonum.rb', line 26 def as @as end |
#operand ⇒ Enumerable (readonly)
23 24 25 |
# File 'lib/alf/engine/autonum.rb', line 23 def operand @operand end |
Instance Method Details
#_each ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/alf/engine/autonum.rb', line 36 def _each autonum = 0 @operand.each do |tuple| yield tuple.merge(@as => autonum) autonum += 1 end end |
#arguments ⇒ Object
44 45 46 |
# File 'lib/alf/engine/autonum.rb', line 44 def arguments [ as ] end |