Class: Twterm::Status
- Inherits:
-
Object
- Object
- Twterm::Status
- Defined in:
- lib/twterm/status.rb
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.
-
#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.
-
#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.
-
#urls ⇒ Object
readonly
Returns the value of attribute urls.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
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.
- #retweet! ⇒ Object
- #retweet? ⇒ Boolean
- #split(width) ⇒ Object
- #unfavorite! ⇒ Object
- #unretweet! ⇒ Object
- #update!(tweet, is_retweeted_status = false) ⇒ Object
Constructor Details
#initialize(tweet, is_retweeted_status = false) ⇒ Status
Returns a new instance of Status.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/twterm/status.rb', line 29 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 = CGI.unescapeHTML(tweet.full_text.dup) @created_at = tweet.created_at.dup.localtime @in_reply_to_status_id = tweet.in_reply_to_status_id update!(tweet, is_retweeted_status) @media = tweet.media @urls = tweet.urls @user_id = tweet.user.id @splitted_text = {} end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
5 6 7 |
# File 'lib/twterm/status.rb', line 5 def created_at @created_at end |
#favorite_count ⇒ Object (readonly)
Returns the value of attribute favorite_count.
5 6 7 |
# File 'lib/twterm/status.rb', line 5 def favorite_count @favorite_count end |
#favorited ⇒ Object (readonly) Also known as: favorited?
Returns the value of attribute favorited.
5 6 7 |
# File 'lib/twterm/status.rb', line 5 def favorited @favorited end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/twterm/status.rb', line 5 def id @id end |
#in_reply_to_status_id ⇒ Object (readonly)
Returns the value of attribute in_reply_to_status_id.
5 6 7 |
# File 'lib/twterm/status.rb', line 5 def in_reply_to_status_id @in_reply_to_status_id end |
#media ⇒ Object (readonly)
Returns the value of attribute media.
5 6 7 |
# File 'lib/twterm/status.rb', line 5 def media @media end |
#retweet_count ⇒ Object (readonly)
Returns the value of attribute retweet_count.
5 6 7 |
# File 'lib/twterm/status.rb', line 5 def retweet_count @retweet_count end |
#retweeted ⇒ Object (readonly) Also known as: retweeted?
Returns the value of attribute retweeted.
5 6 7 |
# File 'lib/twterm/status.rb', line 5 def retweeted @retweeted end |
#retweeted_status_id ⇒ Object (readonly)
Returns the value of attribute retweeted_status_id.
5 6 7 |
# File 'lib/twterm/status.rb', line 5 def retweeted_status_id @retweeted_status_id end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
5 6 7 |
# File 'lib/twterm/status.rb', line 5 def text @text end |
#urls ⇒ Object (readonly)
Returns the value of attribute urls.
5 6 7 |
# File 'lib/twterm/status.rb', line 5 def urls @urls end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
5 6 7 |
# File 'lib/twterm/status.rb', line 5 def user_id @user_id end |
Instance Method Details
#==(other) ⇒ Object
11 12 13 |
# File 'lib/twterm/status.rb', line 11 def ==(other) other.is_a?(self.class) && id == other.id end |
#date ⇒ Object
15 16 17 18 |
# File 'lib/twterm/status.rb', line 15 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
20 21 22 23 |
# File 'lib/twterm/status.rb', line 20 def sub = -> (x) { @text.sub!(x.url, x.display_url) } (@media + @urls).each(&sub) end |
#favorite! ⇒ Object
25 26 27 |
# File 'lib/twterm/status.rb', line 25 def favorite! @favorited = true end |
#retweet! ⇒ Object
55 56 57 |
# File 'lib/twterm/status.rb', line 55 def retweet! @retweeted = true end |
#retweet? ⇒ Boolean
51 52 53 |
# File 'lib/twterm/status.rb', line 51 def retweet? !retweeted_status_id.nil? end |
#split(width) ⇒ Object
59 60 61 |
# File 'lib/twterm/status.rb', line 59 def split(width) @splitted_text[width] ||= @text.split_by_width(width) end |
#unfavorite! ⇒ Object
63 64 65 |
# File 'lib/twterm/status.rb', line 63 def unfavorite! @favorited = false end |
#unretweet! ⇒ Object
67 68 69 |
# File 'lib/twterm/status.rb', line 67 def unretweet! @retweeted = false end |
#update!(tweet, is_retweeted_status = false) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/twterm/status.rb', line 71 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 |