Class: Riffer::StructuredOutput::Result
- Inherits:
-
Object
- Object
- Riffer::StructuredOutput::Result
- Defined in:
- lib/riffer/structured_output/result.rb
Overview
Wraps the result of structured output parsing and validation.
On success, object contains the validated Hash and error is nil. On failure, error contains the error message and object is nil.
result = structured_output.parse_and_validate(json_string)
if result.success?
result.object #=> {sentiment: "positive", score: 0.9}
else
result.error #=> "JSON parse error: ..."
end
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
: String?.
-
#object ⇒ Object
readonly
: Hash[Symbol, untyped]?.
Instance Method Summary collapse
-
#failure? ⇒ Boolean
Returns true when parsing or validation failed.
-
#initialize(object: nil, error: nil) ⇒ Result
constructor
– : (?object: Hash[Symbol, untyped]?, ?error: String?) -> void.
-
#success? ⇒ Boolean
Returns true when parsing and validation succeeded.
Constructor Details
#initialize(object: nil, error: nil) ⇒ Result
– : (?object: Hash[Symbol, untyped]?, ?error: String?) -> void
22 23 24 25 |
# File 'lib/riffer/structured_output/result.rb', line 22 def initialize(object: nil, error: nil) @object = object @error = error end |
Instance Attribute Details
#error ⇒ Object (readonly)
: String?
18 19 20 |
# File 'lib/riffer/structured_output/result.rb', line 18 def error @error end |
#object ⇒ Object (readonly)
: Hash[Symbol, untyped]?
17 18 19 |
# File 'lib/riffer/structured_output/result.rb', line 17 def object @object end |
Instance Method Details
#failure? ⇒ Boolean
Returns true when parsing or validation failed.
– : () -> bool
37 |
# File 'lib/riffer/structured_output/result.rb', line 37 def failure? = !success? |
#success? ⇒ Boolean
Returns true when parsing and validation succeeded.
– : () -> bool
31 |
# File 'lib/riffer/structured_output/result.rb', line 31 def success? = @error.nil? |