Class: LLM::Schema::Object
Overview
The LLM::Schema::Object class represents an object value in a JSON schema. It is a subclass of LLM::Schema::Leaf and provides methods that can act as constraints.
Instance Attribute Summary collapse
- #properties ⇒ Hash readonly
Instance Method Summary collapse
-
#[](key) ⇒ LLM::Schema::Leaf
Get a property.
-
#[]=(key, val)
Set a property.
- #initialize(properties) ⇒ LLM::Schema::Object constructor
- #keys ⇒ Array<String>
-
#merge!(other) ⇒ LLM::Schema::Object
Returns self.
- #to_h ⇒ Hash
- #to_json(options = {}) ⇒ String
Methods inherited from Leaf
#==, #const, #default, #description, #enum, #optional, #optional?, #required?
Constructor Details
#initialize(properties) ⇒ LLM::Schema::Object
18 19 20 |
# File 'lib/llm/schema/object.rb', line 18 def initialize(properties) @properties = properties end |
Instance Attribute Details
#properties ⇒ Hash (readonly)
12 13 14 |
# File 'lib/llm/schema/object.rb', line 12 def properties @properties end |
Instance Method Details
#[](key) ⇒ LLM::Schema::Leaf
Get a property
25 26 27 |
# File 'lib/llm/schema/object.rb', line 25 def [](key) properties[key.to_s] end |
#[]=(key, val)
This method returns an undefined value.
Set a property
32 33 34 |
# File 'lib/llm/schema/object.rb', line 32 def []=(key, val) properties[key.to_s] = val end |
#keys ⇒ Array<String>
61 62 63 |
# File 'lib/llm/schema/object.rb', line 61 def keys @properties.keys end |
#merge!(other) ⇒ LLM::Schema::Object
Returns self
47 48 49 50 51 |
# File 'lib/llm/schema/object.rb', line 47 def merge!(other) raise TypeError, "expected #{self.class} but got #{other.class}" unless self.class === other @properties.merge!(other.properties) self end |
#to_h ⇒ Hash
38 39 40 |
# File 'lib/llm/schema/object.rb', line 38 def to_h super.merge!({type: "object", properties:, required:}) end |
#to_json(options = {}) ⇒ String
55 56 57 |
# File 'lib/llm/schema/object.rb', line 55 def to_json( = {}) to_h.to_json() end |