Class: Ollama::Tool::Function::Parameters::Property

Inherits:
Object
  • Object
show all
Includes:
DTO
Defined in:
lib/ollama/tool/function/parameters/property.rb

Overview

A single property within the parameters specification

Defines an individual parameter with its type, description, and optional enumeration of valid values.

Example:

property = Ollama::Tool::Function::Parameters::Property.new(
type: 'string',
description: 'The location to get weather for'
)

Example with enum:

property = Ollama::Tool::Function::Parameters::Property.new(
type: 'string',
description: 'Temperature unit',
enum: %w[celsius fahrenheit]
)

# Deserialize from hash
property = Ollama::Tool::Function::Parameters::Property.from_hash({ type: 'string', ... })

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DTO

#==, #as_array, #as_array_of_hashes, #as_hash, #empty?, included, #to_json

Constructor Details

#initialize(type:, description:, enum: nil) ⇒ Property

Returns a new instance of Property.



36
37
38
39
40
# File 'lib/ollama/tool/function/parameters/property.rb', line 36

def initialize(type:, description:, enum: nil)
  @type = type.to_s
  @description = description.to_s
  @enum = enum ? Array(enum).map(&:to_s) : nil
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



34
35
36
# File 'lib/ollama/tool/function/parameters/property.rb', line 34

def description
  @description
end

#enumObject (readonly)

Returns the value of attribute enum.



34
35
36
# File 'lib/ollama/tool/function/parameters/property.rb', line 34

def enum
  @enum
end

#typeObject (readonly)

Returns the value of attribute type.



34
35
36
# File 'lib/ollama/tool/function/parameters/property.rb', line 34

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Property

Create instance from hash

Parameters:

  • hash (Hash)

    Hash with type, description, and optional enum keys

Returns:



46
47
48
49
50
51
52
53
# File 'lib/ollama/tool/function/parameters/property.rb', line 46

def self.from_hash(hash)
  normalized = hash.transform_keys(&:to_sym)
  new(
    type: normalized[:type] || normalized["type"],
    description: normalized[:description] || normalized["description"],
    enum: normalized[:enum] || normalized["enum"]
  )
end

Instance Method Details

#as_json(*_ignored) ⇒ Object

Override as_json to use explicit attributes instead of tracked ones



65
66
67
# File 'lib/ollama/tool/function/parameters/property.rb', line 65

def as_json(*_ignored)
  to_h
end

#to_hObject



55
56
57
58
59
60
61
62
# File 'lib/ollama/tool/function/parameters/property.rb', line 55

def to_h
  hash = {
    "type" => @type,
    "description" => @description
  }
  hash["enum"] = @enum if @enum && !@enum.empty?
  hash
end