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
Attributes inherited from Leaf
Instance Method Summary collapse
-
#[](key) ⇒ LLM::Schema::Leaf
Get a property.
-
#[]=(key, val) ⇒ void
Set a property.
- #initialize(properties) ⇒ LLM::Schema::Object constructor
- #keys ⇒ Array<String>
-
#merge!(other) ⇒ LLM::Schema::Object
Returns self.
- #to_h ⇒ Hash
- #to_json ⇒ String
Methods inherited from Leaf
#==, #const, #default, #description, #enum, #optional, #optional?, #required, #required?, #to_s
Constructor Details
#initialize(properties) ⇒ LLM::Schema::Object
18 19 20 21 |
# File 'lib/llm/schema/object.rb', line 18 def initialize(properties) @properties = LLM::Object.new properties.each { set!(_1, _2) } 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
26 27 28 |
# File 'lib/llm/schema/object.rb', line 26 def [](key) properties[key] end |
#[]=(key, val) ⇒ void
This method returns an undefined value.
Set a property
33 34 35 |
# File 'lib/llm/schema/object.rb', line 33 def []=(key, val) set!(key, val) end |
#keys ⇒ Array<String>
62 63 64 |
# File 'lib/llm/schema/object.rb', line 62 def keys @properties.keys end |
#merge!(other) ⇒ LLM::Schema::Object
Returns self
48 49 50 51 52 |
# File 'lib/llm/schema/object.rb', line 48 def merge!(other) raise TypeError, "expected #{self.class} but got #{other.class}" unless self.class === other other.properties.each { |key, val| self[key] = val } self end |
#to_h ⇒ Hash
39 40 41 |
# File 'lib/llm/schema/object.rb', line 39 def to_h super.merge!({type: "object", properties:, required: required_items}) end |