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 22 def initialize(object: nil, error: nil) @object = object @error = error end
Public Instance Methods
Source
# File lib/riffer/structured_output/result.rb, line 37 def failure? = !success? end
Returns true when parsing or validation failed.
Source
# File lib/riffer/structured_output/result.rb, line 31 def success? = @error.nil? # Returns true when parsing or validation failed. # #-- #: () -> bool def failure? = !success?
Returns true when parsing and validation succeeded.