Class: A2A::Types::DataPart
- Defined in:
- lib/a2a/types/part.rb
Overview
Represents a data part in a message
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Attributes inherited from Part
Class Method Summary collapse
-
.from_h(hash) ⇒ DataPart
Create a DataPart from a hash.
Instance Method Summary collapse
-
#initialize(data:, metadata: nil) ⇒ DataPart
constructor
Initialize a new data part.
- #validate! ⇒ Object private
Methods inherited from BaseModel
#==, #camelize, from_json, #hash, #to_h, #to_json, underscore, #valid?, #validate_array_type, #validate_inclusion, #validate_required, #validate_type
Constructor Details
#initialize(data:, metadata: nil) ⇒ DataPart
Initialize a new data part
151 152 153 154 |
# File 'lib/a2a/types/part.rb', line 151 def initialize(data:, metadata: nil) @data = data super(kind: PART_KIND_DATA, metadata: ) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
144 145 146 |
# File 'lib/a2a/types/part.rb', line 144 def data @data end |
Class Method Details
.from_h(hash) ⇒ DataPart
Create a DataPart from a hash
161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/a2a/types/part.rb', line 161 def self.from_h(hash) return hash if hash.is_a?(DataPart) return nil if hash.nil? # Convert string keys to symbols and snake_case camelCase keys normalized_hash = {} hash.each do |key, value| snake_key = BaseModel.underscore(key.to_s).to_sym normalized_hash[snake_key] = value unless snake_key == :kind end new(**normalized_hash) end |
Instance Method Details
#validate! ⇒ Object (private)
177 178 179 180 |
# File 'lib/a2a/types/part.rb', line 177 def validate! super validate_required(:data) end |