Class: A2A::Types::FilePart

Inherits:
Part show all
Defined in:
lib/a2a/types/part.rb

Overview

Represents a file part in a message

Instance Attribute Summary collapse

Attributes inherited from Part

#kind, #metadata

Class Method Summary collapse

Instance Method Summary collapse

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(file:, metadata: nil) ⇒ FilePart

Initialize a new file part



107
108
109
110
# File 'lib/a2a/types/part.rb', line 107

def initialize(file:, metadata: nil)
  @file = file.is_a?(Hash) ? FileBase.from_h(file) : file
  super(kind: PART_KIND_FILE, metadata: )
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



100
101
102
# File 'lib/a2a/types/part.rb', line 100

def file
  @file
end

Class Method Details

.from_h(hash) ⇒ FilePart

Create a FilePart from a hash



117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/a2a/types/part.rb', line 117

def self.from_h(hash)
  return hash if hash.is_a?(FilePart)
  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)



133
134
135
136
137
# File 'lib/a2a/types/part.rb', line 133

def validate!
  super
  validate_required(:file)
  validate_type(:file, FileBase)
end