Class: Alf::Engine::Generator
- Inherits:
-
Object
- Object
- Alf::Engine::Generator
- 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
-
#as ⇒ Symbol
readonly
Name of the autonum attribute.
-
#count ⇒ Integer
readonly
Count number of tuples to generate.
-
#offset ⇒ Integer
readonly
Initial offset.
-
#step ⇒ Integer
readonly
Generation step.
Instance Method Summary collapse
- #_each ⇒ Object
-
#initialize(as, offset, step, count) ⇒ Generator
constructor
Creates an Generator instance.
Methods included from Cog
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
#as ⇒ Symbol (readonly)
Returns Name of the autonum attribute.
20 21 22 |
# File 'lib/alf-engine/alf/engine/generator.rb', line 20 def as @as end |
#count ⇒ Integer (readonly)
Returns Count number of tuples to generate.
29 30 31 |
# File 'lib/alf-engine/alf/engine/generator.rb', line 29 def count @count end |
#offset ⇒ Integer (readonly)
Returns Initial offset.
23 24 25 |
# File 'lib/alf-engine/alf/engine/generator.rb', line 23 def offset @offset end |
#step ⇒ Integer (readonly)
Returns Generation step.
26 27 28 |
# File 'lib/alf-engine/alf/engine/generator.rb', line 26 def step @step end |
Instance Method Details
#_each ⇒ Object
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 |