Class: Twterm::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/twterm/status.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tweet, is_retweeted_status = false) ⇒ Status

Returns a new instance of Status.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/twterm/status.rb', line 40

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
  @quoted_status_id = tweet.quoted_status_id
  @url = tweet.url

  update!(tweet, is_retweeted_status)

  @media = tweet.media
  @hashtags = tweet.hashtags.map { |tag| Hashtag.new(tag) }
  @urls = tweet.urls
  @user_mentions = tweet.user_mentions

  @user_id = tweet.user.id

  @splitted_text = {}

  expand_url!
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



16
17
18
# File 'lib/twterm/status.rb', line 16

def created_at
  @created_at
end

#favorite_countObject (readonly)

Returns the value of attribute favorite_count.



16
17
18
# File 'lib/twterm/status.rb', line 16

def favorite_count
  @favorite_count
end

#favoritedObject (readonly) Also known as: favorited?

Returns the value of attribute favorited.



16
17
18
# File 'lib/twterm/status.rb', line 16

def favorited
  @favorited
end

#hashtagsObject (readonly)

Returns the value of attribute hashtags.



16
17
18
# File 'lib/twterm/status.rb', line 16

def hashtags
  @hashtags
end

#idObject (readonly)

Returns the value of attribute id.



16
17
18
# File 'lib/twterm/status.rb', line 16

def id
  @id
end

#in_reply_to_status_idObject (readonly)

Returns the value of attribute in_reply_to_status_id.



16
17
18
# File 'lib/twterm/status.rb', line 16

def in_reply_to_status_id
  @in_reply_to_status_id
end

#mediaObject (readonly)

Returns the value of attribute media.



16
17
18
# File 'lib/twterm/status.rb', line 16

def media
  @media
end

#quoted_status_idObject (readonly)

Returns the value of attribute quoted_status_id.



16
17
18
# File 'lib/twterm/status.rb', line 16

def quoted_status_id
  @quoted_status_id
end

#retweet_countObject (readonly)

Returns the value of attribute retweet_count.



16
17
18
# File 'lib/twterm/status.rb', line 16

def retweet_count
  @retweet_count
end

#retweetedObject (readonly) Also known as: retweeted?

Returns the value of attribute retweeted.



16
17
18
# File 'lib/twterm/status.rb', line 16

def retweeted
  @retweeted
end

#retweeted_status_idObject (readonly)

Returns the value of attribute retweeted_status_id.



16
17
18
# File 'lib/twterm/status.rb', line 16

def retweeted_status_id
  @retweeted_status_id
end

#textObject (readonly)

Returns the value of attribute text.



16
17
18
# File 'lib/twterm/status.rb', line 16

def text
  @text
end

#urlObject (readonly)

Returns the value of attribute url.



16
17
18
# File 'lib/twterm/status.rb', line 16

def url
  @url
end

#urlsObject (readonly)

Returns the value of attribute urls.



16
17
18
# File 'lib/twterm/status.rb', line 16

def urls
  @urls
end

#user_idObject (readonly)

Returns the value of attribute user_id.



16
17
18
# File 'lib/twterm/status.rb', line 16

def user_id
  @user_id
end

#user_mentionsObject (readonly)

Returns the value of attribute user_mentions.



16
17
18
# File 'lib/twterm/status.rb', line 16

def user_mentions
  @user_mentions
end

Instance Method Details

#==(other) ⇒ Object



22
23
24
# File 'lib/twterm/status.rb', line 22

def ==(other)
  other.is_a?(self.class) && id == other.id
end

#dateObject



26
27
28
29
# File 'lib/twterm/status.rb', line 26

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



31
32
33
34
# File 'lib/twterm/status.rb', line 31

def expand_url!
  sub = -> (x) { @text.sub!(x.url, x.display_url) }
  (@media + @urls).each(&sub)
end

#favorite!Object



36
37
38
# File 'lib/twterm/status.rb', line 36

def favorite!
  @favorited = true
end

#quote?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/twterm/status.rb', line 66

def quote?
  !quoted_status_id.nil?
end

#retweet!Object



74
75
76
# File 'lib/twterm/status.rb', line 74

def retweet!
  @retweeted = true
end

#retweet?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/twterm/status.rb', line 70

def retweet?
  !retweeted_status_id.nil?
end

#split(width) ⇒ Object



78
79
80
# File 'lib/twterm/status.rb', line 78

def split(width)
  @splitted_text[width] ||= @text.split_by_width(width)
end

#unfavorite!Object



82
83
84
# File 'lib/twterm/status.rb', line 82

def unfavorite!
  @favorited = false
end

#unretweet!Object



86
87
88
# File 'lib/twterm/status.rb', line 86

def unretweet!
  @retweeted = false
end

#update!(tweet, is_retweeted_status = false) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/twterm/status.rb', line 90

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