Class: Safubot::Twitter::Tweet
- Inherits:
-
Object
- Object
- Safubot::Twitter::Tweet
- Includes:
- MongoMapper::Document
- Defined in:
- lib/safubot/twitter.rb
Overview
Tweet is both a Request source and general-purpose tweet storage. Mentions are automatically made into Requests, but not timeline tweets.
Class Method Summary collapse
-
.[](id) ⇒ Object
Quickly look up a Tweet.
-
.from(status) ⇒ Object
Find or create a Tweet.
Instance Method Summary collapse
-
#header_mentions ⇒ Object
Retrieve a substring containing the leading mentions.
-
#make_request ⇒ Object
Finds or creates a Request sourced from this Tweet.
-
#original_tweet ⇒ Object
Returns the original tweet of which this is a RT if available.
-
#posted_at ⇒ Object
Returns a Time object specifying the time of publication.
-
#targetless_text ⇒ Object
Plain text without the leading mentions.
-
#text ⇒ Object
The plain text.
-
#user ⇒ Object
Finds or creates a KnownUser connected to this Tweet.
-
#username ⇒ Object
Finds the user’s screen_name.
Class Method Details
.[](id) ⇒ Object
Quickly look up a Tweet.
61 62 63 |
# File 'lib/safubot/twitter.rb', line 61 def [](id) Tweet.where('raw.id' => id).first end |
Instance Method Details
#header_mentions ⇒ Object
Retrieve a substring containing the leading mentions.
85 86 87 88 |
# File 'lib/safubot/twitter.rb', line 85 def header_mentions m = text.match(/(@\w+ )+/) m.nil? ? [] : m[0].split end |
#make_request ⇒ Object
Finds or creates a Request sourced from this Tweet.
111 112 113 |
# File 'lib/safubot/twitter.rb', line 111 def make_request self.request || self.request = Request.create(:user => user, :source => self, :text => self.targetless_text) end |
#original_tweet ⇒ Object
Returns the original tweet of which this is a RT if available.
91 92 93 |
# File 'lib/safubot/twitter.rb', line 91 def original_tweet self.raw['retweeted_status'] && Tweet.from(self.raw['retweeted_status']) end |
#posted_at ⇒ Object
Returns a Time object specifying the time of publication.
106 107 108 |
# File 'lib/safubot/twitter.rb', line 106 def posted_at Time.parse(self.raw['created_at']) end |
#targetless_text ⇒ Object
Plain text without the leading mentions.
80 81 82 |
# File 'lib/safubot/twitter.rb', line 80 def targetless_text text.gsub(/^(@\w+ )+/, '') end |
#text ⇒ Object
The plain text.
75 76 77 |
# File 'lib/safubot/twitter.rb', line 75 def text self.raw['text'] end |
#user ⇒ Object
Finds or creates a KnownUser connected to this Tweet.
96 97 98 |
# File 'lib/safubot/twitter.rb', line 96 def user KnownUser.by_twitter(self.raw['user']['id']) end |
#username ⇒ Object
Finds the user’s screen_name.
101 102 103 |
# File 'lib/safubot/twitter.rb', line 101 def username user.twitter['screen_name'] end |