Class: Boxcars::Observation
- Inherits:
-
Object
- Object
- Boxcars::Observation
- Defined in:
- lib/boxcars/observation.rb
Overview
used by Boxcars to return structured result and additional context
Instance Attribute Summary collapse
-
#added_context ⇒ Object
readonly
Returns the value of attribute added_context.
-
#note ⇒ Object
readonly
Returns the value of attribute note.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
-
.err(note, **kwargs) ⇒ Boxcars::Observation
create a new Observaton from a text string with a status of :error.
-
.ok(note, **kwargs) ⇒ Boxcars::Observation
create a new Observaton from a text string with a status of :ok.
Instance Method Summary collapse
-
#initialize(note:, status: :ok, **added_context) ⇒ Observation
constructor
A new instance of Observation.
-
#to_h ⇒ Hash
The result as a hash.
-
#to_json(*args) ⇒ String
The result as a json string.
-
#to_s ⇒ String
An explanation of the result.
-
#to_text ⇒ String
An explanation of the result.
Constructor Details
#initialize(note:, status: :ok, **added_context) ⇒ Observation
Returns a new instance of Observation.
11 12 13 14 15 |
# File 'lib/boxcars/observation.rb', line 11 def initialize(note:, status: :ok, **added_context) @note = note @status = status @added_context = added_context end |
Instance Attribute Details
#added_context ⇒ Object (readonly)
Returns the value of attribute added_context.
6 7 8 |
# File 'lib/boxcars/observation.rb', line 6 def added_context @added_context end |
#note ⇒ Object (readonly)
Returns the value of attribute note.
6 7 8 |
# File 'lib/boxcars/observation.rb', line 6 def note @note end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/boxcars/observation.rb', line 6 def status @status end |
Class Method Details
.err(note, **kwargs) ⇒ Boxcars::Observation
create a new Observaton from a text string with a status of :error
52 53 54 |
# File 'lib/boxcars/observation.rb', line 52 def self.err(note, **kwargs) new(note: note, status: :error, **kwargs) end |
.ok(note, **kwargs) ⇒ Boxcars::Observation
create a new Observaton from a text string with a status of :ok
44 45 46 |
# File 'lib/boxcars/observation.rb', line 44 def self.ok(note, **kwargs) new(note: note, status: :ok, **kwargs) end |
Instance Method Details
#to_h ⇒ Hash
Returns The result as a hash.
18 19 20 21 22 23 |
# File 'lib/boxcars/observation.rb', line 18 def to_h { note: note, status: status }.merge(added_context).compact end |
#to_json(*args) ⇒ String
Returns The result as a json string.
26 27 28 |
# File 'lib/boxcars/observation.rb', line 26 def to_json(*args) JSON.generate(to_h, *args) end |
#to_s ⇒ String
Returns An explanation of the result.
31 32 33 |
# File 'lib/boxcars/observation.rb', line 31 def to_s note.to_s end |
#to_text ⇒ String
Returns An explanation of the result.
36 37 38 |
# File 'lib/boxcars/observation.rb', line 36 def to_text to_s end |