Class: OpenRouter::Schema::ItemsBuilder
- Inherits:
-
Object
- Object
- OpenRouter::Schema::ItemsBuilder
- Defined in:
- lib/open_router/schema.rb
Overview
Internal class for building array items
Instance Method Summary collapse
- #boolean(description: nil, **options) ⇒ Object
-
#initialize ⇒ ItemsBuilder
constructor
A new instance of ItemsBuilder.
- #integer(description: nil, **options) ⇒ Object
- #number(description: nil, **options) ⇒ Object
- #object(&block) ⇒ Object
- #string(description: nil, **options) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ ItemsBuilder
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, **) @items = { type: "boolean" } @items[:description] = description if description @items.merge!() end |
#integer(description: nil, **options) ⇒ Object
249 250 251 252 253 |
# File 'lib/open_router/schema.rb', line 249 def integer(description: nil, **) @items = { type: "integer" } @items[:description] = description if description @items.merge!() end |
#number(description: nil, **options) ⇒ Object
255 256 257 258 259 |
# File 'lib/open_router/schema.rb', line 255 def number(description: nil, **) @items = { type: "number" } @items[:description] = description if description @items.merge!() 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, **) @items = { type: "string" } @items[:description] = description if description @items.merge!() end |
#to_h ⇒ Object
283 284 285 |
# File 'lib/open_router/schema.rb', line 283 def to_h @items end |