Class: Ibex::TableSimulation::Result
- Inherits:
-
Object
- Object
- Ibex::TableSimulation::Result
- Defined in:
- lib/ibex/table_simulation/result.rb
Overview
Final immutable simulation document.
Constant Summary collapse
- IDENTIFIER =
"table-simulation"- SCHEMA_VERSION =
: String
1
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
readonly
: String.
-
#grammar_digest ⇒ Object
readonly
: Integer.
-
#status ⇒ Object
readonly
: Symbol.
-
#steps ⇒ Object
readonly
: Array.
-
#tokens ⇒ Object
readonly
: Array.
Instance Method Summary collapse
-
#initialize(grammar_digest:, algorithm:, tokens:, status:, steps:) ⇒ Result
constructor
A new instance of Result.
- #to_h ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(grammar_digest:, algorithm:, tokens:, status:, steps:) ⇒ Result
Returns a new instance of Result.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ibex/table_simulation/result.rb', line 25 def initialize(grammar_digest:, algorithm:, tokens:, status:, steps:) raise ArgumentError, "simulation status must be accepted or error" unless %i[accepted error].include?(status) @grammar_digest = grammar_digest.dup.freeze @algorithm = algorithm.dup.freeze @tokens = tokens.map { |token| token.dup.freeze }.freeze @status = status @steps = steps.dup.freeze freeze end |
Instance Attribute Details
#algorithm ⇒ Object (readonly)
: String
18 19 20 |
# File 'lib/ibex/table_simulation/result.rb', line 18 def algorithm @algorithm end |
#grammar_digest ⇒ Object (readonly)
: Integer
17 18 19 |
# File 'lib/ibex/table_simulation/result.rb', line 17 def grammar_digest @grammar_digest end |
#status ⇒ Object (readonly)
: Symbol
20 21 22 |
# File 'lib/ibex/table_simulation/result.rb', line 20 def status @status end |
#steps ⇒ Object (readonly)
: Array
21 22 23 |
# File 'lib/ibex/table_simulation/result.rb', line 21 def steps @steps end |
#tokens ⇒ Object (readonly)
: Array
19 20 21 |
# File 'lib/ibex/table_simulation/result.rb', line 19 def tokens @tokens end |
Instance Method Details
#to_h ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ibex/table_simulation/result.rb', line 37 def to_h { "ibex_table_simulation" => IDENTIFIER, "schema_version" => SCHEMA_VERSION, "grammar_digest" => @grammar_digest, "algorithm" => @algorithm, "tokens" => @tokens, "status" => @status.to_s, "steps" => @steps.map(&:to_h) } end |
#to_json ⇒ Object
50 51 52 |
# File 'lib/ibex/table_simulation/result.rb', line 50 def to_json(*) "#{JSON.pretty_generate(to_h)}\n" end |