Class: OpenRouter::Schema::ItemsBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/open_router/schema.rb

Overview

Internal class for building array items

Instance Method Summary collapse

Constructor Details

#initializeItemsBuilder

Returns a new instance of ItemsBuilder.



239
240
241
# File 'lib/open_router/schema.rb', line 239

def initialize
  @items = {}
end

Instance Method Details

#boolean(description: nil, **options) ⇒ Object



261
262
263
264
265
# File 'lib/open_router/schema.rb', line 261

def boolean(description: nil, **options)
  @items = { type: "boolean" }
  @items[:description] = description if description
  @items.merge!(options)
end

#integer(description: nil, **options) ⇒ Object



249
250
251
252
253
# File 'lib/open_router/schema.rb', line 249

def integer(description: nil, **options)
  @items = { type: "integer" }
  @items[:description] = description if description
  @items.merge!(options)
end

#number(description: nil, **options) ⇒ Object



255
256
257
258
259
# File 'lib/open_router/schema.rb', line 255

def number(description: nil, **options)
  @items = { type: "number" }
  @items[:description] = description if description
  @items.merge!(options)
end

#object(&block) ⇒ Object



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/open_router/schema.rb', line 267

def object(&block)
  @items = { type: "object", properties: {}, required: [], additionalProperties: false }

  return unless block_given?

  object_builder = SchemaBuilder.new
  object_builder.instance_eval(&block)
  nested_schema = object_builder.to_h
  @items[:properties] = nested_schema[:properties]
  @items[:required] = nested_schema[:required]
  return unless nested_schema.key?(:additionalProperties)

  @items[:additionalProperties] =
    nested_schema[:additionalProperties]
end

#string(description: nil, **options) ⇒ Object



243
244
245
246
247
# File 'lib/open_router/schema.rb', line 243

def string(description: nil, **options)
  @items = { type: "string" }
  @items[:description] = description if description
  @items.merge!(options)
end

#to_hObject



283
284
285
# File 'lib/open_router/schema.rb', line 283

def to_h
  @items
end