class Tweet

Attributes

doc[R]
html[R]
replies[RW]
reply_counter[RW]
url[R]
user[R]

Public Class Methods

new(url, user=nil) click to toggle source
# File lib/twiterator/tweet.rb, line 5
def initialize(url, user=nil)
  @html = open(url)
  @doc = Nokogiri::HTML(html)
  @url = url
  @user = user
  # Had these as setter/getters but it was more efficient to scale them down into methods:
  # @content = doc.css('.js-tweet-text-container p')[0].text
  # @display_name = doc.css('.permalink-header fullname').text
  # @user_name = doc.css('.js-action-profile-name b')[0].text.strip
  # @time = doc.css('.client-and-actions').text.strip.split(" - ")[0]
  # @date = doc.css('.client-and-actions').text.strip.split(" - ")[1]
  @replies = []
  # @retweets = doc.css('.request-retweeted-popup strong').text
  # @likes = doc.css('.js-stat-favorites strong').text
end

Public Instance Methods

content() click to toggle source
# File lib/twiterator/tweet.rb, line 21
def content
  doc.css('.js-tweet-text-container p')[0].text
end
date() click to toggle source
# File lib/twiterator/tweet.rb, line 37
def date
  doc.css('.client-and-actions').text.strip.split(" - ")[1]
end
display_name() click to toggle source
# File lib/twiterator/tweet.rb, line 25
def display_name
  doc.css('.permalink-header fullname').text
end
likes() click to toggle source
# File lib/twiterator/tweet.rb, line 45
def likes
  doc.css('.js-stat-favorites strong').text
end
reply_count() click to toggle source
# File lib/twiterator/tweet.rb, line 49
def reply_count
  self.doc.css('.ProfileTweet-actionCount')[0].text.strip.gsub(/[^0-9]/, "").to_i
end
retweeted?() click to toggle source
# File lib/twiterator/tweet.rb, line 53
def retweeted?
  self.user_name.downcase != self.user.user_name.downcase || false
end
retweets() click to toggle source
# File lib/twiterator/tweet.rb, line 41
def retweets
  doc.css('.request-retweeted-popup strong').text
end
set_replies() click to toggle source
# File lib/twiterator/tweet.rb, line 57
def set_replies
  reply_counter = 0
  #binding.pry
  # The code snippet in "reply_count" reads off the number of replies that there are, then would have helped this method loop for exactly that many times. Sadly, twitter only displays 15 replies to ruby, so I had to settle for a 15-iteration loop. So now the method just checks to see if the reply count is UNDER 15.
  (reply_count < 15 ? reply_count : 16).times do
      parent_tweet = self
      self.replies << Reply.new(reply_counter, parent_tweet)
      reply_counter += 1
    end
  self.replies.pop
end
time() click to toggle source
# File lib/twiterator/tweet.rb, line 33
def time
  doc.css('.client-and-actions').text.strip.split(" - ")[0]
end
user_name() click to toggle source
# File lib/twiterator/tweet.rb, line 29
def user_name
  doc.css('.js-action-profile-name b')[0].text.strip
end