Module: Ultrasafeai::Internal::Types::Enum

Includes:
Type
Included in:
AudioStream::Types::AudioStreamAudioFormat, Chat::Completions::Types::CreateCompletionsRequestMessagesItemContentRole, Chat::Completions::Types::CreateCompletionsRequestReasoningEffort, Chat::Completions::Types::CreateCompletionsStreamRequestMessagesItemContentRole, Chat::Completions::Types::CreateCompletionsStreamRequestReasoningEffort, Embeddings::Types::CreateEmbeddingsRequestEncodingFormat, Files::Types::ListFilesRequestOrder, Ultrasafeai::Images::Types::GenerateImagesRequestResponseFormat, Ultrasafeai::Images::Types::GenerateImagesRequestSize, Ocr::Types::ExtractOcrRequestExtractionTarget, Ocr::Types::StreamOcrRequestExtractionTarget, Parser::Types::ParseParserRequestExtractionTarget, Parser::Types::ParseParserRequestParse, Parser::Types::StreamParserRequestExtractionTarget, Parser::Types::StreamParserRequestParse, Types::ChatCompletionAssistantMessageParamRole, Types::ChatCompletionChoicesItemFinishReason, Types::ChatCompletionChoicesItemMessageAnnotationsItemType, Types::ChatCompletionChoicesItemMessageRole, Types::ChatCompletionChunkChoicesItemDeltaRole, Types::ChatCompletionChunkChoicesItemDeltaToolCallsItemType, Types::ChatCompletionChunkChoicesItemFinishReason, Types::ChatCompletionChunkObject, Types::ChatCompletionChunkServiceTier, Types::ChatCompletionCustomToolCustomFormatGrammarGrammarSyntax, Types::ChatCompletionCustomToolType, Types::ChatCompletionObject, Types::ChatCompletionServiceTier, Types::ChatCompletionToolChoiceOptionAllowedToolsAllowedToolsMode, Types::ChatCompletionToolChoiceOptionAllowedToolsType, Types::ChatCompletionToolChoiceOptionCustomType, Types::ChatCompletionToolChoiceOptionFunctionType, Types::ChatCompletionToolChoiceOptionZero, Types::ChatCompletionToolMessageParamContentOneItemType, Types::ChatCompletionToolMessageParamRole, Types::EmbeddingObject, Types::EmbeddingResponseObject, Types::ModelObject, Types::TranscriptEventType, Types::UltraparserCollectionObject, Types::UltraparserOcrResponseObject, Types::UltraparserProgressEventStatus, Ultraparser::Types::FilesearchRequestMessagesItemRole, Ultraparser::Types::ListCollectionsResponseObject
Defined in:
lib/ultrasafeai/internal/types/enum.rb

Overview

Module for defining enums

Instance Method Summary collapse

Methods included from JSON::Serializable

#dump

Instance Method Details

#coerce(value, strict: strict?) ) ⇒ Object

Raises:



32
33
34
35
36
37
38
39
40
# File 'lib/ultrasafeai/internal/types/enum.rb', line 32

def coerce(value, strict: strict?)
  coerced_value = Utils.coerce(Symbol, value)

  return coerced_value if values.include?(coerced_value)

  raise Errors::TypeError, "`#{value}` not in enum #{self}" if strict

  value
end

#finalize!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



18
19
20
# File 'lib/ultrasafeai/internal/types/enum.rb', line 18

def finalize!
  values
end

#inspectObject



50
51
52
# File 'lib/ultrasafeai/internal/types/enum.rb', line 50

def inspect
  "#{name}[#{values.join(", ")}]"
end

#load(str) ⇒ String

Parse JSON string and coerce to the enum value

Parameters:

  • str (String)

    JSON string to parse

Returns:

  • (String)

    The enum value



46
47
48
# File 'lib/ultrasafeai/internal/types/enum.rb', line 46

def load(str)
  coerce(::JSON.parse(str))
end

#strict!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
# File 'lib/ultrasafeai/internal/types/enum.rb', line 28

def strict!
  @strict = true
end

#strict?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



23
24
25
# File 'lib/ultrasafeai/internal/types/enum.rb', line 23

def strict?
  @strict ||= false
end

#valuesArray<Object>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



13
14
15
# File 'lib/ultrasafeai/internal/types/enum.rb', line 13

def values
  @values ||= constants.map { |c| const_get(c) }
end