Class: Whatsapp::Messages::Template::Language

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/ruby/whatsapp/messages/template/language.rb

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:) ⇒ Language

Returns a new instance of Language.

Parameters:

  • code (String)

    The language code (e.g., "en_US", "pt_BR"). @raise [ActiveModel::ValidationError] if validation fails.



19
20
21
22
23
# File 'lib/ruby/whatsapp/messages/template/language.rb', line 19

def initialize(code:)
  @code = code

  validate!
end

Instance Attribute Details

#codeString

Returns:

  • (String)


13
14
15
# File 'lib/ruby/whatsapp/messages/template/language.rb', line 13

def code
  @code
end

Class Method Details

.serialize(code:) ⇒ Hash

Serializes the language to a hash format suitable for the WhatsApp API.

Parameters:

  • code (String)

    The language code.

Returns:

  • (Hash)

    The serialized language.



37
38
39
# File 'lib/ruby/whatsapp/messages/template/language.rb', line 37

def serialize(code:)
  new(code:).serialize
end

Instance Method Details

#serializeHash

Serializes the language to a hash format suitable for the WhatsApp API.

Returns:

  • (Hash)

    The serialized language.



27
28
29
30
31
# File 'lib/ruby/whatsapp/messages/template/language.rb', line 27

def serialize
  {
    code:,
  }
end