Class: PositionalGenerator
- Inherits:
-
Object
- Object
- PositionalGenerator
- Defined in:
- lib/helpers/positional_generator.rb
Overview
A high level way to generate a list of generated values that fit a specific format, such as an ID, postal code, or phone number.
It provides generators for random digits and letters, hardcoded literal strings, computed values based on previously-generated values, union (one-of) selectors, and grouped generators.
The generation allows for dependencies on previously generated values – most useful for computations – and this object knows how to build that dependency graph.
See Builder for more.
Defined Under Namespace
Instance Method Summary collapse
-
#generate ⇒ String
If
as_type
is:string
. -
#initialize(as_type, &block) ⇒ PositionalGenerator
constructor
A new instance of PositionalGenerator.
Constructor Details
#initialize(as_type, &block) ⇒ PositionalGenerator
Returns a new instance of PositionalGenerator.
20 21 22 23 |
# File 'lib/helpers/positional_generator.rb', line 20 def initialize(as_type, &block) @block = block @generator_builder = Builder.new(as_type) end |
Instance Method Details
#generate ⇒ String
Returns if as_type
is :string
.
27 28 29 30 |
# File 'lib/helpers/positional_generator.rb', line 27 def generate @block.call(@generator_builder) @generator_builder.build end |