Class: Alf::Engine::Generator

Inherits:
Object
  • Object
show all
Includes:
Cog
Defined in:
lib/alf/engine/generator.rb

Overview

Generates tuples with an integer attributes, with an initial offset and a step.

Example:

Generator.new(3, :id, 10, 5).to_a
# => [
#      {:id => 10},
#      {:id => 15},
#      {:id => 20}
#    ]

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(as, offset, step, count, expr = nil, compiler = nil) ⇒ Generator

Creates an Generator instance


32
33
34
35
36
37
38
# File 'lib/alf/engine/generator.rb', line 32

def initialize(as, offset, step, count, expr = nil, compiler = nil)
  super(expr, compiler)
  @as = as
  @offset = offset
  @step = step
  @count = count
end

Instance Attribute Details

#asSymbol (readonly)


20
21
22
# File 'lib/alf/engine/generator.rb', line 20

def as
  @as
end

#countInteger (readonly)


29
30
31
# File 'lib/alf/engine/generator.rb', line 29

def count
  @count
end

#offsetInteger (readonly)


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

def offset
  @offset
end

#stepInteger (readonly)


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

def step
  @step
end

Instance Method Details

#_eachObject


41
42
43
44
45
46
47
# File 'lib/alf/engine/generator.rb', line 41

def _each
  cur = offset
  count.times do |i|
    yield(@as => cur)
    cur += step
  end
end

#argumentsObject


49
50
51
# File 'lib/alf/engine/generator.rb', line 49

def arguments
  [ offset, step, count ]
end