Class: A2A::Artifact

Inherits:
Object
  • Object
show all
Defined in:
lib/a2a/artifact.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, parts:, **kwargs) ⇒ Artifact

Returns a new instance of Artifact.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
# File 'lib/a2a/artifact.rb', line 7

def initialize(id:, parts:, **kwargs)
  raise ArgumentError, "parts must contain at least one element" if Array(parts).empty?

  @id = id
  @parts = parts
  @name = kwargs[:name]
  @description = kwargs[:description]
  @extensions = kwargs[:extensions]
  @metadata = kwargs[:metadata]
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/a2a/artifact.rb', line 5

def description
  @description
end

#extensionsObject (readonly)

Returns the value of attribute extensions.



5
6
7
# File 'lib/a2a/artifact.rb', line 5

def extensions
  @extensions
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/a2a/artifact.rb', line 5

def id
  @id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



5
6
7
# File 'lib/a2a/artifact.rb', line 5

def 
  @metadata
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/a2a/artifact.rb', line 5

def name
  @name
end

#partsObject (readonly)

Returns the value of attribute parts.



5
6
7
# File 'lib/a2a/artifact.rb', line 5

def parts
  @parts
end

Class Method Details

.from_h(hash) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/a2a/artifact.rb', line 18

def self.from_h(hash)
  new(
    id: hash.fetch("artifactId"),
    name: hash["name"],
    description: hash["description"],
    parts: Array(hash["parts"]).map { Part.from_h(_1) },
    extensions: hash["extensions"],
    metadata: hash["metadata"]
  )
end

Instance Method Details

#to_hObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/a2a/artifact.rb', line 29

def to_h
  {
    "parts" => parts.map(&:to_h),
    "artifactId" => id,
    "name" => name,
    "description" => description,
    "extensions" => extensions,
    "metadata" => 
  }.compact
end