Class: Twterm::DirectMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/twterm/direct_message.rb

Defined Under Namespace

Classes: Conversation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ DirectMessage

Returns a new instance of DirectMessage.



8
9
10
11
# File 'lib/twterm/direct_message.rb', line 8

def initialize(message)
  @id = message.id
  update!(message)
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



6
7
8
# File 'lib/twterm/direct_message.rb', line 6

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/twterm/direct_message.rb', line 6

def id
  @id
end

#recipient_idObject (readonly)

Returns the value of attribute recipient_id.



6
7
8
# File 'lib/twterm/direct_message.rb', line 6

def recipient_id
  @recipient_id
end

#sender_idObject (readonly)

Returns the value of attribute sender_id.



6
7
8
# File 'lib/twterm/direct_message.rb', line 6

def sender_id
  @sender_id
end

#textObject (readonly)

Returns the value of attribute text.



6
7
8
# File 'lib/twterm/direct_message.rb', line 6

def text
  @text
end

Instance Method Details

#==(other) ⇒ Object



13
14
15
# File 'lib/twterm/direct_message.rb', line 13

def ==(other)
  other.is_a?(self.class) && id == other.id
end

#dateObject



17
18
19
20
# File 'lib/twterm/direct_message.rb', line 17

def date
  format = Time.now - @created_at < 86_400 ? '%H:%M:%S' : '%Y-%m-%d %H:%M:%S'
  @created_at.strftime(format)
end

#update!(message) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/twterm/direct_message.rb', line 22

def update!(message)
  @created_at = message.created_at.dup.localtime
  @recipient_id = message.recipient.id
  @sender_id = message.sender.id
  @text = message.text

  self
end