Class: Alf::Engine::Autonum

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

Attributes included from Compiler::Cog

#compiler, #expr

Instance Method Summary collapse

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

#asSymbol (readonly)


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

def as
  @as
end

#operandEnumerable (readonly)


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

def operand
  @operand
end

Instance Method Details

#_eachObject


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

#argumentsObject


44
45
46
# File 'lib/alf/engine/autonum.rb', line 44

def arguments
  [ as ]
end