class Calyx::Options

Provides access to configuration options while evaluating a grammar.

Constants

DEFAULTS

These options are used by default if not explicitly provided during initialization of the grammar.

Public Class Methods

new(options={}) click to toggle source

Constructs a new options instance, merging the passed in options with the defaults.

@param [Hash, Calyx::Options] options

# File lib/calyx/options.rb, line 14
def initialize(options={})
  @options = DEFAULTS.merge(options)
end

Public Instance Methods

merge(options) click to toggle source

Merges two instances together and returns a new instance.

@param [Calyx::Options] options @return [Calyx::Options]

# File lib/calyx/options.rb, line 59
def merge(options)
  Options.new(@options.merge(options.to_h))
end
rand() click to toggle source

Returns the next pseudo-random number in the sequence defined by the internal random number generator state.

The value returned is a floating point number between 0.0 and 1.0, including 0.0 and excluding 1.0.

@return [Float]

# File lib/calyx/options.rb, line 42
def rand
  rng.rand
end
rng() click to toggle source

Returns the internal random number generator instance. If a seed or random instance is not passed-in directly, a new instance of `Random` is initialized by default.

@return [Random]

# File lib/calyx/options.rb, line 23
def rng
  unless @options[:rng]
    @options[:rng] = if @options[:seed]
      Random.new(@options[:seed])
    else
      Random.new
    end
  end

  @options[:rng]
end
strict?() click to toggle source

True if the strict mode option is enabled. This option defines whether or not to raise an error on missing rules. When set to false, missing rules are skipped over when the production is concatenated.

@return [TrueClass, FalseClass]

# File lib/calyx/options.rb, line 51
def strict?
  @options[:strict]
end
to_h() click to toggle source

Serializes instance data to a hash.

@return [Hash]

# File lib/calyx/options.rb, line 66
def to_h
  @options.dup
end