Class: OpenRouter::Tool::ItemsBuilder
- Inherits:
-
Object
- Object
- OpenRouter::Tool::ItemsBuilder
- Defined in:
- lib/open_router/tool.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
- #items(schema = nil, &block) ⇒ 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.
167 168 169 |
# File 'lib/open_router/tool.rb', line 167 def initialize @items = {} end |
Instance Method Details
#boolean(description: nil, **options) ⇒ Object
183 184 185 |
# File 'lib/open_router/tool.rb', line 183 def boolean(description: nil, **) @items = { type: "boolean", description: }.merge().compact end |
#integer(description: nil, **options) ⇒ Object
175 176 177 |
# File 'lib/open_router/tool.rb', line 175 def integer(description: nil, **) @items = { type: "integer", description: }.merge().compact end |
#items(schema = nil, &block) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/open_router/tool.rb', line 201 def items(schema = nil, &block) # This method allows for `array { items { object { ... }}}` or `items(hash)` if block_given? # Block defines what each item in the array looks like nested_builder = ItemsBuilder.new nested_builder.instance_eval(&block) @items = nested_builder.to_h elsif schema.is_a?(Hash) # Direct hash schema assignment @items = schema else raise ArgumentError, "items must be called with either a hash or a block" end end |
#number(description: nil, **options) ⇒ Object
179 180 181 |
# File 'lib/open_router/tool.rb', line 179 def number(description: nil, **) @items = { type: "number", description: }.merge().compact end |
#object(&block) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/open_router/tool.rb', line 187 def object(&block) @items = { type: "object", properties: {}, required: [], additionalProperties: false } return unless block_given? nested = Tool::ParametersBuilder.new(@items) nested.instance_eval(&block) end |
#string(description: nil, **options) ⇒ Object
171 172 173 |
# File 'lib/open_router/tool.rb', line 171 def string(description: nil, **) @items = { type: "string", description: }.merge().compact end |
#to_h ⇒ Object
216 217 218 |
# File 'lib/open_router/tool.rb', line 216 def to_h @items end |