Class: A2A::Types::TextPart

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

Overview

Represents a text 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(text:, metadata: nil) ⇒ TextPart

Initialize a new text part

Parameters:

  • The text content

  • (defaults to: nil)

    Additional metadata



63
64
65
66
# File 'lib/a2a/types/part.rb', line 63

def initialize(text:, metadata: nil)
  @text = text
  super(kind: PART_KIND_TEXT, metadata: )
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



56
57
58
# File 'lib/a2a/types/part.rb', line 56

def text
  @text
end

Class Method Details

.from_h(hash) ⇒ TextPart

Create a TextPart from a hash

Parameters:

  • The hash representation

Returns:

  • The new instance



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/a2a/types/part.rb', line 73

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



89
90
91
92
93
# File 'lib/a2a/types/part.rb', line 89

def validate!
  super
  validate_required(:text)
  validate_type(:text, String)
end