Class: Twterm::Status
- Inherits:
-
Object
- Object
- Twterm::Status
- Defined in:
- lib/twterm/status.rb
Overview
A tweet
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#favorite_count ⇒ Object
readonly
Returns the value of attribute favorite_count.
-
#favorited ⇒ Object
(also: #favorited?)
readonly
Returns the value of attribute favorited.
-
#hashtags ⇒ Object
readonly
Returns the value of attribute hashtags.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#in_reply_to_status_id ⇒ Object
readonly
Returns the value of attribute in_reply_to_status_id.
-
#media ⇒ Object
readonly
Returns the value of attribute media.
-
#quoted_status_id ⇒ Object
readonly
Returns the value of attribute quoted_status_id.
-
#retweet_count ⇒ Object
readonly
Returns the value of attribute retweet_count.
-
#retweeted ⇒ Object
(also: #retweeted?)
readonly
Returns the value of attribute retweeted.
-
#retweeted_status_id ⇒ Object
readonly
Returns the value of attribute retweeted_status_id.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#urls ⇒ Object
readonly
Returns the value of attribute urls.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
-
#user_mentions ⇒ Object
readonly
Returns the value of attribute user_mentions.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #date ⇒ Object
- #expand_url! ⇒ Object
- #favorite! ⇒ Object
-
#initialize(tweet, is_retweeted_status = false) ⇒ Status
constructor
A new instance of Status.
-
#quote? ⇒ Boolean
Is this status a quote?.
- #retweet! ⇒ Object
-
#retweet? ⇒ Boolean
Is this status a retweet?.
- #split(width) ⇒ Object
- #unfavorite! ⇒ Object
- #unretweet! ⇒ Object
- #update!(tweet, is_retweeted_status = false) ⇒ self
Constructor Details
#initialize(tweet, is_retweeted_status = false) ⇒ Status
Returns a new instance of Status.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/twterm/status.rb', line 43 def initialize(tweet, is_retweeted_status = false) unless tweet.retweeted_status.is_a? Twitter::NullObject @retweeted_status_id = tweet.retweeted_status.id end @id = tweet.id text = if tweet.truncated? && tweet.attrs[:extended_tweet] tweet.attrs[:extended_tweet][:full_text] else tweet.attrs[:text] || tweet.attrs[:full_text] end @text = CGI.unescapeHTML(text) @created_at = tweet.created_at.dup.localtime @in_reply_to_status_id = tweet.in_reply_to_status_id @quoted_status_id = tweet.quoted_status_id @url = tweet.url update!(tweet, is_retweeted_status) @media = tweet.media @hashtags = tweet..map { |tag| Hashtag.new(tag) } @urls = tweet.urls @user_mentions = tweet.user_mentions @user_id = tweet.user.id @splitted_text = {} end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
17 18 19 |
# File 'lib/twterm/status.rb', line 17 def created_at @created_at end |
#favorite_count ⇒ Object (readonly)
Returns the value of attribute favorite_count.
17 18 19 |
# File 'lib/twterm/status.rb', line 17 def favorite_count @favorite_count end |
#favorited ⇒ Object (readonly) Also known as: favorited?
Returns the value of attribute favorited.
17 18 19 |
# File 'lib/twterm/status.rb', line 17 def favorited @favorited end |
#hashtags ⇒ Object (readonly)
Returns the value of attribute hashtags.
17 18 19 |
# File 'lib/twterm/status.rb', line 17 def @hashtags end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
17 18 19 |
# File 'lib/twterm/status.rb', line 17 def id @id end |
#in_reply_to_status_id ⇒ Object (readonly)
Returns the value of attribute in_reply_to_status_id.
17 18 19 |
# File 'lib/twterm/status.rb', line 17 def in_reply_to_status_id @in_reply_to_status_id end |
#media ⇒ Object (readonly)
Returns the value of attribute media.
17 18 19 |
# File 'lib/twterm/status.rb', line 17 def media @media end |
#quoted_status_id ⇒ Object (readonly)
Returns the value of attribute quoted_status_id.
17 18 19 |
# File 'lib/twterm/status.rb', line 17 def quoted_status_id @quoted_status_id end |
#retweet_count ⇒ Object (readonly)
Returns the value of attribute retweet_count.
17 18 19 |
# File 'lib/twterm/status.rb', line 17 def retweet_count @retweet_count end |
#retweeted ⇒ Object (readonly) Also known as: retweeted?
Returns the value of attribute retweeted.
17 18 19 |
# File 'lib/twterm/status.rb', line 17 def retweeted @retweeted end |
#retweeted_status_id ⇒ Object (readonly)
Returns the value of attribute retweeted_status_id.
17 18 19 |
# File 'lib/twterm/status.rb', line 17 def retweeted_status_id @retweeted_status_id end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
17 18 19 |
# File 'lib/twterm/status.rb', line 17 def text @text end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
17 18 19 |
# File 'lib/twterm/status.rb', line 17 def url @url end |
#urls ⇒ Object (readonly)
Returns the value of attribute urls.
17 18 19 |
# File 'lib/twterm/status.rb', line 17 def urls @urls end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
17 18 19 |
# File 'lib/twterm/status.rb', line 17 def user_id @user_id end |
#user_mentions ⇒ Object (readonly)
Returns the value of attribute user_mentions.
17 18 19 |
# File 'lib/twterm/status.rb', line 17 def user_mentions @user_mentions end |
Instance Method Details
#==(other) ⇒ Object
23 24 25 |
# File 'lib/twterm/status.rb', line 23 def ==(other) other.is_a?(self.class) && id == other.id end |
#date ⇒ Object
28 29 30 31 |
# File 'lib/twterm/status.rb', line 28 def date format = Time.now - @created_at < 86_400 ? '%H:%M:%S' : '%Y-%m-%d %H:%M:%S' @created_at.strftime(format) end |
#expand_url! ⇒ Object
34 35 36 37 |
# File 'lib/twterm/status.rb', line 34 def sub = -> (x) { @text.sub!(x.url, x.display_url) } (@media + @urls).each(&sub) end |
#favorite! ⇒ Object
39 40 41 |
# File 'lib/twterm/status.rb', line 39 def favorite! @favorited = true end |
#quote? ⇒ Boolean
Is this status a quote?
78 79 80 |
# File 'lib/twterm/status.rb', line 78 def quote? !quoted_status_id.nil? end |
#retweet! ⇒ Object
89 90 91 |
# File 'lib/twterm/status.rb', line 89 def retweet! @retweeted = true end |
#retweet? ⇒ Boolean
Is this status a retweet?
85 86 87 |
# File 'lib/twterm/status.rb', line 85 def retweet? !retweeted_status_id.nil? end |
#split(width) ⇒ Object
93 94 95 |
# File 'lib/twterm/status.rb', line 93 def split(width) @splitted_text[width] ||= @text.split_by_width(width) end |
#unfavorite! ⇒ Object
97 98 99 |
# File 'lib/twterm/status.rb', line 97 def unfavorite! @favorited = false end |
#unretweet! ⇒ Object
101 102 103 |
# File 'lib/twterm/status.rb', line 101 def unretweet! @retweeted = false end |
#update!(tweet, is_retweeted_status = false) ⇒ self
106 107 108 109 110 111 112 113 |
# File 'lib/twterm/status.rb', line 106 def update!(tweet, is_retweeted_status = false) @retweet_count = tweet.retweet_count @favorite_count = tweet.favorite_count @retweeted = tweet.retweeted? unless is_retweeted_status @favorited = tweet.favorited? self end |