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 =
: String
"table-simulation"- SCHEMA_VERSION =
: Integer
1
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
readonly
: String.
-
#grammar_digest ⇒ Object
readonly
: String.
-
#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.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ibex/table_simulation/result.rb', line 21 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
14 15 16 |
# File 'lib/ibex/table_simulation/result.rb', line 14 def algorithm @algorithm end |
#grammar_digest ⇒ Object (readonly)
: String
13 14 15 |
# File 'lib/ibex/table_simulation/result.rb', line 13 def grammar_digest @grammar_digest end |
#status ⇒ Object (readonly)
: Symbol
16 17 18 |
# File 'lib/ibex/table_simulation/result.rb', line 16 def status @status end |
#steps ⇒ Object (readonly)
: Array
17 18 19 |
# File 'lib/ibex/table_simulation/result.rb', line 17 def steps @steps end |
#tokens ⇒ Object (readonly)
: Array
15 16 17 |
# File 'lib/ibex/table_simulation/result.rb', line 15 def tokens @tokens end |
Instance Method Details
#to_h ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ibex/table_simulation/result.rb', line 33 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
46 47 48 |
# File 'lib/ibex/table_simulation/result.rb', line 46 def to_json(*) "#{JSON.pretty_generate(to_h)}\n" end |