Class: A2A::Models::Part
- Inherits:
-
Base
- Object
- Base
- A2A::Models::Part
show all
- Defined in:
- lib/simple_a2a/models/part.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#==, attribute, attributes, from_hash, inherited, #initialize, #to_h, #to_json
Class Method Details
.binary(bytes, media_type:, filename: nil) ⇒ Object
26
27
28
|
# File 'lib/simple_a2a/models/part.rb', line 26
def self.binary(bytes, media_type:, filename: nil)
new(raw: Base64.strict_encode64(bytes), media_type: media_type, filename: filename)
end
|
.from_url(url, media_type:, filename: nil) ⇒ Object
22
23
24
|
# File 'lib/simple_a2a/models/part.rb', line 22
def self.from_url(url, media_type:, filename: nil)
new(url: url, media_type: media_type, filename: filename)
end
|
.json(hash, filename: nil) ⇒ Object
18
19
20
|
# File 'lib/simple_a2a/models/part.rb', line 18
def self.json(hash, filename: nil)
new(data: hash, media_type: "application/json", filename: filename)
end
|
.text(content, media_type: "text/plain", filename: nil) ⇒ Object
14
15
16
|
# File 'lib/simple_a2a/models/part.rb', line 14
def self.text(content, media_type: "text/plain", filename: nil)
new(text: content, media_type: media_type, filename: filename)
end
|
Instance Method Details
#decoded_bytes ⇒ Object
35
36
37
38
|
# File 'lib/simple_a2a/models/part.rb', line 35
def decoded_bytes
return nil unless raw
Base64.strict_decode64(raw)
end
|
#json? ⇒ Boolean
31
|
# File 'lib/simple_a2a/models/part.rb', line 31
def json? = !data.nil?
|
#raw? ⇒ Boolean
33
|
# File 'lib/simple_a2a/models/part.rb', line 33
def raw? = !raw.nil?
|
#text? ⇒ Boolean
30
|
# File 'lib/simple_a2a/models/part.rb', line 30
def text? = !text.nil?
|
#url? ⇒ Boolean
32
|
# File 'lib/simple_a2a/models/part.rb', line 32
def url? = !url.nil?
|
#valid? ⇒ Boolean
40
41
42
|
# File 'lib/simple_a2a/models/part.rb', line 40
def valid?
[text, raw, url, data].compact.length == 1
end
|