Class: PositionalGenerator

Inherits:
Object
  • Object
show all
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

Classes: Builder, Component

Instance Method Summary collapse

Constructor Details

#initialize(as_type, &block) ⇒ PositionalGenerator

Returns a new instance of PositionalGenerator.

Parameters:

  • as_type (Symbol)

    :string to generate a String

  • block (Method)

    a function that interacts with the Builder



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

#generateString

Returns if as_type is :string.

Returns:

  • (String)

    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