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.



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

def initialize
  @items = {}
end

Instance Method Details

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



277
278
279
280
281
# File 'lib/open_router/schema.rb', line 277

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

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



265
266
267
268
269
# File 'lib/open_router/schema.rb', line 265

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

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



271
272
273
274
275
# File 'lib/open_router/schema.rb', line 271

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

#object(&block) ⇒ Object



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/open_router/schema.rb', line 283

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



259
260
261
262
263
# File 'lib/open_router/schema.rb', line 259

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

#to_hObject



299
300
301
# File 'lib/open_router/schema.rb', line 299

def to_h
  @items
end