Class: Succubus::Result

Inherits:
String
  • Object
show all
Defined in:
lib/succubus/result.rb

Overview

Class containing the result of executing a Grammar.

Result is a subclass of String, so it can be used exactly as if it were a String. Its main purpose is to provide access to metadata about the execution that produced it - namely the random_seed used, and any errors produced.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seed, *args, &block) ⇒ Result

Create a new Result

Parameters:

  • seed (Integer)

    The random seed used to generate this result

  • args (Array)

    Passed through to super

  • block (Proc)

    Passed through to super



25
26
27
28
# File 'lib/succubus/result.rb', line 25

def initialize(seed, *args, &block)
  @random_seed = seed
  super(*args, &block)
end

Instance Attribute Details

#errorsArray<String> (readonly)

Returns Any errors that occurred during the generation of this Succubus::Result.

Returns:

  • (Array<String>)

    Any errors that occurred during the generation of this Succubus::Result.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/succubus/result.rb', line 15

class Result < String
  attr_reader :random_seed, :errors

  # Create a new Result
  #
  # @private
  #
  # @param [Integer] seed The random seed used to generate this result
  # @param [Array] args Passed through to +super+
  # @param [Proc] block Passed through to +super+
  def initialize(seed, *args, &block)
    @random_seed = seed
    super(*args, &block)
  end

  # Set the errors encountered creating this Result
  #
  # @private
  #
  # @param [Array<String>] errors the errors encountered
  def set_errors(errors)
    @errors = errors
  end
end

#random_seedInteger (readonly)

Returns The random seed used to generate this Result. #random_seed can be passed to Grammar#execute to exactly repeat the process that generated this Succubus::Result (for possible debugging purposes, or reporting issues).

Returns:

  • (Integer)

    The random seed used to generate this Result. #random_seed can be passed to Grammar#execute to exactly repeat the process that generated this Succubus::Result (for possible debugging purposes, or reporting issues)



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/succubus/result.rb', line 15

class Result < String
  attr_reader :random_seed, :errors

  # Create a new Result
  #
  # @private
  #
  # @param [Integer] seed The random seed used to generate this result
  # @param [Array] args Passed through to +super+
  # @param [Proc] block Passed through to +super+
  def initialize(seed, *args, &block)
    @random_seed = seed
    super(*args, &block)
  end

  # Set the errors encountered creating this Result
  #
  # @private
  #
  # @param [Array<String>] errors the errors encountered
  def set_errors(errors)
    @errors = errors
  end
end

Instance Method Details

#set_errors(errors) ⇒ Object

Set the errors encountered creating this Result

Parameters:

  • errors (Array<String>)

    the errors encountered



35
36
37
# File 'lib/succubus/result.rb', line 35

def set_errors(errors)
  @errors = errors
end