Class: Twterm::DirectMessage::Conversation
- Inherits:
-
Object
- Object
- Twterm::DirectMessage::Conversation
- Includes:
- Utils
- Defined in:
- lib/twterm/direct_message.rb
Instance Attribute Summary collapse
-
#collocutor ⇒ Object
readonly
Returns the value of attribute collocutor.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
- #<<(message) ⇒ Object
-
#initialize(collocutor) ⇒ Conversation
constructor
A new instance of Conversation.
- #matches?(q) ⇒ Boolean
- #preview ⇒ Object
- #updated_at ⇒ Object
Methods included from Utils
Constructor Details
#initialize(collocutor) ⇒ Conversation
Returns a new instance of Conversation.
48 49 50 51 52 53 |
# File 'lib/twterm/direct_message.rb', line 48 def initialize(collocutor) check_type User, collocutor @collocutor = collocutor @messages = [] end |
Instance Attribute Details
#collocutor ⇒ Object (readonly)
Returns the value of attribute collocutor.
46 47 48 |
# File 'lib/twterm/direct_message.rb', line 46 def collocutor @collocutor end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
46 47 48 |
# File 'lib/twterm/direct_message.rb', line 46 def @messages end |
Instance Method Details
#<<(message) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/twterm/direct_message.rb', line 55 def <<() @messages << if .find { |m| m == }.nil? @messages.sort_by!(&:created_at).reverse! self end |
#matches?(q) ⇒ Boolean
62 63 64 65 66 67 68 |
# File 'lib/twterm/direct_message.rb', line 62 def matches?(q) [ collocutor.screen_name, collocutor.name, preview ].map(&:downcase).any? { |x| x.include?(q.downcase) } end |
#preview ⇒ Object
70 71 72 |
# File 'lib/twterm/direct_message.rb', line 70 def preview .sort_by(&:created_at).last.text.gsub("\n", ' ') end |
#updated_at ⇒ Object
74 75 76 77 78 79 |
# File 'lib/twterm/direct_message.rb', line 74 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 |