Class: Alf::Engine::Generator

Inherits:
Object
  • Object
show all
Includes:
Cog
Defined in:
lib/alf-engine/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}
#    ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cog

#each, #to_dot, #to_relation

Constructor Details

#initialize(as, offset, step, count) ⇒ Generator

Creates an Generator instance



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

def initialize(as, offset, step, count)
  @as = as
  @offset = offset
  @step = step
  @count = count
end

Instance Attribute Details

#asSymbol (readonly)

Returns Name of the autonum attribute.

Returns:

  • (Symbol)

    Name of the autonum attribute



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

def as
  @as
end

#countInteger (readonly)

Returns Count number of tuples to generate.

Returns:

  • (Integer)

    Count number of tuples to generate



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

def count
  @count
end

#offsetInteger (readonly)

Returns Initial offset.

Returns:

  • (Integer)

    Initial offset



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

def offset
  @offset
end

#stepInteger (readonly)

Returns Generation step.

Returns:

  • (Integer)

    Generation step



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

def step
  @step
end

Instance Method Details

#_eachObject



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

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