class PositionalGenerator

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 {PositionalGenerator::Builder} for more.

Constants

Component

Public Class Methods

new(as_type, &block) click to toggle source

@param as_type [Symbol] :string to generate a String @param block [Method] a function that interacts with the {Builder}

# File lib/helpers/positional_generator.rb, line 20
def initialize(as_type, &block)
  @block = block
  @generator_builder = Builder.new(as_type)
end

Public Instance Methods

generate() click to toggle source

@return [String] if as_type is :string

# File lib/helpers/positional_generator.rb, line 27
def generate
  @block.call(@generator_builder)
  @generator_builder.build
end