Class: Message

Inherits:
Object
  • Object
show all
Defined in:
lib/models/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Message

Returns a new instance of Message.



6
7
8
9
# File 'lib/models/message.rb', line 6

def initialize(json)
  json.each { |key, value| instance_variable_set("@#{key}", value) }
  @attachments = @attachments&.map { |attachment| Attachment.new(attachment) }
end

Instance Attribute Details

#attachmentsObject

Returns the value of attribute attachments.



4
5
6
# File 'lib/models/message.rb', line 4

def attachments
  @attachments
end

#fromObject

Returns the value of attribute from.



4
5
6
# File 'lib/models/message.rb', line 4

def from
  @from
end

#htmlObject

Returns the value of attribute html.



4
5
6
# File 'lib/models/message.rb', line 4

def html
  @html
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/models/message.rb', line 4

def id
  @id
end

#subjectObject

Returns the value of attribute subject.



4
5
6
# File 'lib/models/message.rb', line 4

def subject
  @subject
end

#textObject

Returns the value of attribute text.



4
5
6
# File 'lib/models/message.rb', line 4

def text
  @text
end

#toObject

Returns the value of attribute to.



4
5
6
# File 'lib/models/message.rb', line 4

def to
  @to
end

Instance Method Details

#to_sObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/models/message.rb', line 11

def to_s
  <<~MESSAGE
    ID: #{@id}
    From: #{@from}
    To: #{@to}
    Subject: #{@subject}
    Text: #{@text}
    HTML: #{@html}
    Attachments: #{@attachments.map(&:to_s).join("\n")}
  MESSAGE
end