Class: EmailAddress

Inherits:
Object
  • Object
show all
Defined in:
lib/email_api/email/data/email_address.rb

Overview

Contains all parameters that defines an email address

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, email = name) ⇒ EmailAddress

Returns a new instance of EmailAddress.



6
7
8
9
# File 'lib/email_api/email/data/email_address.rb', line 6

def initialize(name = nil, email = name)
  @name  = name
  @email = email
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



4
5
6
# File 'lib/email_api/email/data/email_address.rb', line 4

def email
  @email
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/email_api/email/data/email_address.rb', line 3

def name
  @name
end

Instance Method Details

#to_hashObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/email_api/email/data/email_address.rb', line 11

def to_hash
  hash = {}
  instance_variables.each do |var|
    name       = var.to_s.delete('@')
    value      = instance_variable_get(var)
    val_hash   = value.to_hash if value.respond_to?(:to_hash)
    hash[name] = val_hash.nil? ? value : val_hash
  end
  hash
end