Class: Whatsapp::Messages::Contacts::Email

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

Overview

Represents an email entry in a contact message.

Defined Under Namespace

Modules: Types

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email:, type: nil) ⇒ Email

Returns a new instance of Email.

Parameters:

  • email (String)

    The email address.

  • type (String, nil) (defaults to: nil)

    Email type. One of HOME, WORK, OTHER. @raise [ActiveModel::ValidationError] if validation fails.



32
33
34
35
36
37
# File 'lib/ruby/whatsapp/messages/contacts/email.rb', line 32

def initialize(email:, type: nil)
  @email = email
  @type = type

  validate!
end

Instance Attribute Details

#emailString

Returns:

  • (String)


20
21
22
# File 'lib/ruby/whatsapp/messages/contacts/email.rb', line 20

def email
  @email
end

#typeString?

Returns:

  • (String, nil)


24
25
26
# File 'lib/ruby/whatsapp/messages/contacts/email.rb', line 24

def type
  @type
end

Instance Method Details

#serializeHash

Returns The serialized email payload.

Returns:

  • (Hash)

    The serialized email payload.



40
41
42
43
44
45
# File 'lib/ruby/whatsapp/messages/contacts/email.rb', line 40

def serialize
  {
    email:,
    type:,
  }.compact
end