Class: Olfactory::Sequence
- Inherits:
-
Hash
- Object
- Hash
- Olfactory::Sequence
- Defined in:
- lib/olfactory/sequence.rb
Instance Method Summary collapse
- #generate(name, options, block) ⇒ Object
-
#initialize(name, options, block) ⇒ Sequence
constructor
A new instance of Sequence.
- #reset ⇒ Object
Constructor Details
#initialize(name, options, block) ⇒ Sequence
Returns a new instance of Sequence.
4 5 6 7 8 9 10 |
# File 'lib/olfactory/sequence.rb', line 4 def initialize(name, , block) self[:name] = name self[:evaluator] = block self[:scope] = ([:scope] || :global) self[:seed] = ([:seed] || 0) self[:current_seed] = ([:seed] || 0) end |
Instance Method Details
#generate(name, options, block) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/olfactory/sequence.rb', line 12 def generate(name, , block) seed = [:seed] || self[:current_seed] target = block || self[:evaluator] value = target.call(seed, .reject { |k,v| k == :seed }) self[:current_seed] += 1 if !.has_key?(:seed) value end |
#reset ⇒ Object
20 21 22 |
# File 'lib/olfactory/sequence.rb', line 20 def reset self[:current_seed] = self[:seed] end |