Class: Alf::Engine::Autonum

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Cog

#each, #to_dot, #to_relation

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

#asSymbol (readonly)

Returns Name of the autonum attribute.

Returns:

  • (Symbol)

    Name of the autonum attribute



26
27
28
# File 'lib/alf-engine/alf/engine/autonum.rb', line 26

def as
  @as
end

#operandEnumerable (readonly)

Returns The operand.

Returns:

  • (Enumerable)

    The operand



23
24
25
# File 'lib/alf-engine/alf/engine/autonum.rb', line 23

def operand
  @operand
end

Instance Method Details

#_eachObject



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