class User
Attributes
counter[RW]
display_name[RW]
doc[RW]
tweets[RW]
user_name[RW]
Public Class Methods
new(user_name)
click to toggle source
# File lib/twiterator/user.rb, line 4 def initialize(user_name) html = open("https://twitter.com/#{user_name}") @doc = Nokogiri::HTML(html) @user_name = user_name @display_name = @doc.css('.ProfileHeaderCard-nameLink').text.strip @tweets = [] end
Public Instance Methods
five_more()
click to toggle source
# File lib/twiterator/user.rb, line 48 def five_more this_counter = counter + 5 until counter == this_counter tweet_cycle end end
follower_count()
click to toggle source
# File lib/twiterator/user.rb, line 33 def follower_count self.doc.css('.ProfileNav-item--followers a')[0].attr('title') end
following_count()
click to toggle source
# File lib/twiterator/user.rb, line 37 def following_count self.doc.css('.ProfileNav-item--following a')[0].attr('title') end
get_tweet()
click to toggle source
# File lib/twiterator/user.rb, line 73 def get_tweet user = self path = self.doc.css('.js-stream-tweet')[counter].values[3] url = "https://www.twitter.com#{path}" self.tweets << Tweet.new(url, user) end
private?()
click to toggle source
def real_account?
rescue OpenURI::HTTPError => error response = error.io !response.status.include?("404" || "Not Found")
end
# File lib/twiterator/user.rb, line 29 def private? self.doc.css('.ProtectedTimeline h2').text == "This account's Tweets are protected." || false end
redisplay()
click to toggle source
# File lib/twiterator/user.rb, line 55 def redisplay self.tweets.each_with_index do |tweet, index| puts "#{(index+1).to_s}. #{tweet.date} - #{tweet.time} -#{"**RETWEET**" if tweet.retweeted?}- #{tweet.content}" puts " " end end
show_five()
click to toggle source
# File lib/twiterator/user.rb, line 41 def show_five @counter = 0 until self.counter == 5 tweet_cycle end end
tweet()
click to toggle source
# File lib/twiterator/user.rb, line 68 def tweet puts "#{(self.counter + 1).to_s}. #{self.tweets[self.counter].date} -#{"**RETWEET**" if tweets[counter].retweeted?}- #{self.tweets[self.counter].content}\n" puts " " end
tweet_cycle()
click to toggle source
# File lib/twiterator/user.rb, line 62 def tweet_cycle get_tweet tweet self.counter += 1 end