Class: Twterm::Status
- Inherits:
-
Object
- Object
- Twterm::Status
- Defined in:
- lib/twterm/status.rb
Constant Summary collapse
- @@instances =
[]
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#created_at_for_sort ⇒ Object
readonly
Returns the value of attribute created_at_for_sort.
-
#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_by ⇒ Object
readonly
Returns the value of attribute retweeted_by.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#urls ⇒ Object
readonly
Returns the value of attribute urls.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
- .find_by_in_reply_to_status_id(in_reply_to_status_id) ⇒ Object
- .new(tweet) ⇒ Object
- .parse_time(time) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #date ⇒ Object
- #expand_url! ⇒ Object
- #favorite! ⇒ Object
- #in_reply_to_status(&block) ⇒ Object
-
#initialize(tweet) ⇒ Status
constructor
A new instance of Status.
- #retweet! ⇒ Object
- #split(width) ⇒ Object
- #unfavorite! ⇒ Object
- #update!(tweet) ⇒ Object
Constructor Details
#initialize(tweet) ⇒ Status
Returns a new instance of Status.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/twterm/status.rb', line 15 def initialize(tweet) unless tweet.retweeted_status.is_a? Twitter::NullObject @retweeted_by = User.new(tweet.user) retweeted_at = Status.parse_time(tweet.created_at) tweet = tweet.retweeted_status end @id = tweet.id @text = CGI.unescapeHTML(tweet.full_text.dup) @created_at = Status.parse_time(tweet.created_at) @created_at_for_sort = retweeted_at || @created_at @retweet_count = tweet.retweet_count @favorite_count = tweet.favorite_count @in_reply_to_status_id = tweet.in_reply_to_status_id @retweeted = tweet.retweeted? @favorited = tweet.favorited? @media = tweet.media @urls = tweet.urls @user = User.new(tweet.user) @splitted_text = {} @@instances << self end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
3 4 5 |
# File 'lib/twterm/status.rb', line 3 def created_at @created_at end |
#created_at_for_sort ⇒ Object (readonly)
Returns the value of attribute created_at_for_sort.
3 4 5 |
# File 'lib/twterm/status.rb', line 3 def created_at_for_sort @created_at_for_sort end |
#favorite_count ⇒ Object (readonly)
Returns the value of attribute favorite_count.
3 4 5 |
# File 'lib/twterm/status.rb', line 3 def favorite_count @favorite_count end |
#favorited ⇒ Object (readonly) Also known as: favorited?
Returns the value of attribute favorited.
3 4 5 |
# File 'lib/twterm/status.rb', line 3 def favorited @favorited end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/twterm/status.rb', line 3 def id @id end |
#in_reply_to_status_id ⇒ Object (readonly)
Returns the value of attribute in_reply_to_status_id.
3 4 5 |
# File 'lib/twterm/status.rb', line 3 def in_reply_to_status_id @in_reply_to_status_id end |
#media ⇒ Object (readonly)
Returns the value of attribute media.
3 4 5 |
# File 'lib/twterm/status.rb', line 3 def media @media end |
#retweet_count ⇒ Object (readonly)
Returns the value of attribute retweet_count.
3 4 5 |
# File 'lib/twterm/status.rb', line 3 def retweet_count @retweet_count end |
#retweeted ⇒ Object (readonly) Also known as: retweeted?
Returns the value of attribute retweeted.
3 4 5 |
# File 'lib/twterm/status.rb', line 3 def retweeted @retweeted end |
#retweeted_by ⇒ Object (readonly)
Returns the value of attribute retweeted_by.
3 4 5 |
# File 'lib/twterm/status.rb', line 3 def retweeted_by @retweeted_by end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
3 4 5 |
# File 'lib/twterm/status.rb', line 3 def text @text end |
#urls ⇒ Object (readonly)
Returns the value of attribute urls.
3 4 5 |
# File 'lib/twterm/status.rb', line 3 def urls @urls end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
3 4 5 |
# File 'lib/twterm/status.rb', line 3 def user @user end |
Class Method Details
.find_by_in_reply_to_status_id(in_reply_to_status_id) ⇒ Object
93 94 95 |
# File 'lib/twterm/status.rb', line 93 def find_by_in_reply_to_status_id(in_reply_to_status_id) @@instances.find { |status| status.id == in_reply_to_status_id } end |
.new(tweet) ⇒ Object
9 10 11 12 13 |
# File 'lib/twterm/status.rb', line 9 def self.new(tweet) detector = -> (instance) { instance.id == tweet.id } instance = @@instances.find(&detector) instance.nil? ? super : instance.update!(tweet) end |
.parse_time(time) ⇒ Object
97 98 99 |
# File 'lib/twterm/status.rb', line 97 def parse_time(time) (time.is_a?(String) ? Time.parse(time) : time.dup).localtime end |
Instance Method Details
#==(other) ⇒ Object
88 89 90 |
# File 'lib/twterm/status.rb', line 88 def ==(other) other.is_a?(self.class) && id == other.id end |
#date ⇒ Object
53 54 55 56 |
# File 'lib/twterm/status.rb', line 53 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
58 59 60 61 |
# File 'lib/twterm/status.rb', line 58 def sub = -> (x) { @text.sub!(x.url, x.display_url) } (@media + @urls).each(&sub) end |
#favorite! ⇒ Object
63 64 65 |
# File 'lib/twterm/status.rb', line 63 def favorite! @favorited = true end |
#in_reply_to_status(&block) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/twterm/status.rb', line 79 def in_reply_to_status(&block) block.call(nil) if @in_reply_to_status_id.nil? status = Status.find_by_in_reply_to_status_id(@in_reply_to_status_id) block.call(status) unless status.nil? Client.current.show_status(@in_reply_to_status_id, &block) end |
#retweet! ⇒ Object
71 72 73 |
# File 'lib/twterm/status.rb', line 71 def retweet! @retweeted = true end |
#split(width) ⇒ Object
75 76 77 |
# File 'lib/twterm/status.rb', line 75 def split(width) @splitted_text[:width] ||= @text.split_by_width(width) end |
#unfavorite! ⇒ Object
67 68 69 |
# File 'lib/twterm/status.rb', line 67 def unfavorite! @favorited = false end |
#update!(tweet) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/twterm/status.rb', line 45 def update!(tweet) @retweet_count = tweet.retweet_count @favorite_count = tweet.favorite_count @retweeted = tweet.retweeted? @favorited = tweet.favorited? self end |