Class: EmailObject

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

Overview

Contains all parameters that defines an email

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*params) ⇒ EmailObject

Returns a new instance of EmailObject.



10
11
12
13
14
15
16
17
# File 'lib/email_api/email/data/email_object.rb', line 10

def initialize(*params)
  @from    = params[0]
  @to      = params[1]
  @cc      = params[2]
  @bcc     = params[3]
  @subject = params[4]
  @content = params[5]
end

Instance Attribute Details

#bccObject

Returns the value of attribute bcc.



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

def bcc
  @bcc
end

#ccObject

Returns the value of attribute cc.



5
6
7
# File 'lib/email_api/email/data/email_object.rb', line 5

def cc
  @cc
end

#contentObject

Returns the value of attribute content.



8
9
10
# File 'lib/email_api/email/data/email_object.rb', line 8

def content
  @content
end

#fromObject

Returns the value of attribute from.



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

def from
  @from
end

#subjectObject

Returns the value of attribute subject.



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

def subject
  @subject
end

#toObject

Returns the value of attribute to.



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

def to
  @to
end

Instance Method Details

#==(other) ⇒ Object



19
20
21
22
# File 'lib/email_api/email/data/email_object.rb', line 19

def ==(other)
  return false unless other.respond_to?(:to_hash)
  to_hash == other.to_hash
end

#to_hashObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/email_api/email/data/email_object.rb', line 24

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)

    # Array doesn't implicitly convert to hash automatically
    if val_hash.nil? && value.is_a?(Array)
      val_hash = []
      value.each do |val|
        val_hash.push val.to_hash if val.respond_to?(:to_hash)
      end
    end

    hash[name] = val_hash.nil? ? value : val_hash
  end
  hash
end