Class: Anthropic::Helpers::InputSchema::EnumOf

Inherits:
Object
  • Object
show all
Includes:
JsonSchemaConverter, Internal::Type::Enum
Defined in:
lib/anthropic/helpers/input_schema/enum_of.rb

Overview

Examples:

example = Anthropic::EnumOf[:foo, :bar, :zoo]
example = Anthropic::EnumOf[1, 2, 3]

Generic:

  • Value

Constant Summary

Constants included from JsonSchemaConverter

JsonSchemaConverter::NO_REF, JsonSchemaConverter::POINTERS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from JsonSchemaConverter

assoc_meta!, cache_def!, to_json_schema, to_json_schema_inner, to_nilable

Methods included from Internal::Type::Enum

#==, #===, #coerce, #dump, #hash, #inspect, #to_sorbet_type

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Methods included from Internal::Type::Converter

#coerce, coerce, #dump, dump, inspect, #inspect, meta_info, new_coerce_state, type_info

Constructor Details

#initialize(*values) ⇒ EnumOf



59
# File 'lib/anthropic/helpers/input_schema/enum_of.rb', line 59

def initialize(*values) = (@values = values.map { _1.is_a?(String) ? _1.to_sym : _1 })

Instance Attribute Details

#valuesArray<generic<Value>> (readonly)



56
57
58
# File 'lib/anthropic/helpers/input_schema/enum_of.rb', line 56

def values
  @values
end

Class Method Details

.[]void



53
# File 'lib/anthropic/helpers/input_schema/enum_of.rb', line 53

def self.[](...) = new(...)

Instance Method Details

#to_json_schema_inner(state:) ⇒ Hash{Symbol=>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.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/anthropic/helpers/input_schema/enum_of.rb', line 26

def to_json_schema_inner(state:)
  Anthropic::Helpers::InputSchema::JsonSchemaConverter.cache_def!(state, type: self) do
    types = values.map do
      case _1
      in NilClass
        "null"
      in true | false
        "boolean"
      in Integer
        "integer"
      in Float
        "number"
      in Symbol
        "string"
      end
    end
      .uniq

    {
      type: types.length == 1 ? types.first : types,
      enum: values.map { _1.is_a?(Symbol) ? _1.to_s : _1 }
    }
  end
end