class Riffer::StructuredOutput::Result
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
Attributes
Public Class Methods
Source
# File lib/riffer/structured_output/result.rb, line 21 def initialize(object: nil, error: nil) @object = object @error = error end
: (?object: Hash[Symbol, untyped]?, ?error: String?) -> void
Public Instance Methods
Source
# File lib/riffer/structured_output/result.rb, line 34 def failure? = !success? end
Returns true when parsing or validation failed.
: () -> bool
Source
# File lib/riffer/structured_output/result.rb, line 29 def success? = @error.nil? # Returns true when parsing or validation failed. # #: () -> bool def failure? = !success?
Returns true when parsing and validation succeeded.
: () -> bool