Class: Twterm::DirectMessage::Conversation
- Inherits:
-
Object
- Object
- Twterm::DirectMessage::Conversation
- Includes:
- Utils
- Defined in:
- lib/twterm/direct_message.rb
Instance Attribute Summary collapse
-
#collocutor_id ⇒ Object
readonly
Returns the value of attribute collocutor_id.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
- #<<(message) ⇒ Object
-
#initialize(collocutor_id) ⇒ Conversation
constructor
A new instance of Conversation.
- #preview ⇒ Object
- #updated_at ⇒ Object
Methods included from Utils
Constructor Details
#initialize(collocutor_id) ⇒ Conversation
Returns a new instance of Conversation.
36 37 38 39 |
# File 'lib/twterm/direct_message.rb', line 36 def initialize(collocutor_id) @collocutor_id = collocutor_id @messages = [] end |
Instance Attribute Details
#collocutor_id ⇒ Object (readonly)
Returns the value of attribute collocutor_id.
34 35 36 |
# File 'lib/twterm/direct_message.rb', line 34 def collocutor_id @collocutor_id end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
34 35 36 |
# File 'lib/twterm/direct_message.rb', line 34 def @messages end |
Instance Method Details
#<<(message) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/twterm/direct_message.rb', line 41 def <<() @messages << if .find { |m| m == }.nil? @messages.sort_by!(&:created_at).reverse! self end |
#preview ⇒ Object
48 49 50 |
# File 'lib/twterm/direct_message.rb', line 48 def preview .sort_by(&:created_at).last.text.gsub("\n", ' ') end |
#updated_at ⇒ Object
52 53 54 55 56 57 |
# File 'lib/twterm/direct_message.rb', line 52 def updated_at updated_at = @messages.map(&:created_at).max format = Time.now - updated_at < 86_400 ? '%H:%M:%S' : '%Y-%m-%d %H:%M:%S' updated_at.strftime(format) end |