Class: A2A::Types::FileWithBytes
- Defined in:
- lib/a2a/types/part.rb
Overview
Represents a file with base64-encoded bytes
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
-
#mime_type ⇒ Object
readonly
Returns the value of attribute mime_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#content ⇒ String
Get the decoded file content.
-
#initialize(name:, mime_type:, bytes:) ⇒ FileWithBytes
constructor
Initialize a new file with bytes.
-
#size ⇒ Integer
Get the file size in bytes.
- #validate! ⇒ Object private
Methods inherited from FileBase
Methods inherited from BaseModel
#==, #camelize, from_h, from_json, #hash, #to_h, #to_json, underscore, #valid?, #validate_array_type, #validate_inclusion, #validate_required, #validate_type
Constructor Details
#initialize(name:, mime_type:, bytes:) ⇒ FileWithBytes
Initialize a new file with bytes
217 218 219 220 221 222 |
# File 'lib/a2a/types/part.rb', line 217 def initialize(name:, mime_type:, bytes:) @name = name @mime_type = mime_type @bytes = bytes validate! end |
Instance Attribute Details
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
209 210 211 |
# File 'lib/a2a/types/part.rb', line 209 def bytes @bytes end |
#mime_type ⇒ Object (readonly)
Returns the value of attribute mime_type.
209 210 211 |
# File 'lib/a2a/types/part.rb', line 209 def mime_type @mime_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
209 210 211 |
# File 'lib/a2a/types/part.rb', line 209 def name @name end |
Instance Method Details
#content ⇒ String
Get the decoded file content
228 229 230 231 |
# File 'lib/a2a/types/part.rb', line 228 def content require "base64" Base64.decode64(@bytes) end |
#size ⇒ Integer
Get the file size in bytes
237 238 239 |
# File 'lib/a2a/types/part.rb', line 237 def size content.bytesize end |
#validate! ⇒ Object (private)
243 244 245 246 247 248 |
# File 'lib/a2a/types/part.rb', line 243 def validate! validate_required(:name, :mime_type, :bytes) validate_type(:name, String) validate_type(:mime_type, String) validate_type(:bytes, String) end |