Class: Succubus::Result
- Inherits:
-
String
- Object
- String
- Succubus::Result
- 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
-
#errors ⇒ Array<String>
readonly
Any errors that occurred during the generation of this Result.
-
#random_seed ⇒ Integer
readonly
The random seed used to generate this Result.
Instance Method Summary collapse
-
#initialize(seed, *args, &block) ⇒ Result
constructor
Create a new Result.
-
#set_errors(errors) ⇒ Object
Set the errors encountered creating this Result.
Constructor Details
#initialize(seed, *args, &block) ⇒ Result
Create a new Result
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
#errors ⇒ Array<String> (readonly)
Returns 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_seed ⇒ Integer (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).
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
35 36 37 |
# File 'lib/succubus/result.rb', line 35 def set_errors(errors) @errors = errors end |