Class: Alf::Engine::Autonum
- Inherits:
-
Object
- Object
- Alf::Engine::Autonum
- Includes:
- Cog
- Defined in:
- lib/alf-engine/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}
# ]
Instance Attribute Summary collapse
-
#as ⇒ Symbol
readonly
Name of the autonum attribute.
-
#operand ⇒ Enumerable
readonly
The operand.
Instance Method Summary collapse
- #_each ⇒ Object
-
#initialize(operand, as) ⇒ Autonum
constructor
Creates an Autonum instance.
Methods included from Cog
Constructor Details
#initialize(operand, as) ⇒ Autonum
Creates an Autonum instance
29 30 31 32 |
# File 'lib/alf-engine/alf/engine/autonum.rb', line 29 def initialize(operand, as) @operand = operand @as = as end |
Instance Attribute Details
#as ⇒ Symbol (readonly)
Returns Name of the autonum attribute.
26 27 28 |
# File 'lib/alf-engine/alf/engine/autonum.rb', line 26 def as @as end |
#operand ⇒ Enumerable (readonly)
Returns The operand.
23 24 25 |
# File 'lib/alf-engine/alf/engine/autonum.rb', line 23 def operand @operand end |
Instance Method Details
#_each ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/alf-engine/alf/engine/autonum.rb', line 35 def _each autonum = 0 @operand.each do |tuple| yield tuple.merge(@as => autonum) autonum += 1 end end |