Class: User
- Inherits:
-
Object
- Object
- User
- Defined in:
- lib/twiterator/user.rb
Instance Attribute Summary collapse
-
#counter ⇒ Object
Returns the value of attribute counter.
-
#display_name ⇒ Object
Returns the value of attribute display_name.
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#tweets ⇒ Object
Returns the value of attribute tweets.
-
#user_name ⇒ Object
Returns the value of attribute user_name.
Instance Method Summary collapse
- #five_more ⇒ Object
- #follower_count ⇒ Object
- #following_count ⇒ Object
- #get_tweet ⇒ Object
-
#initialize(user_name) ⇒ User
constructor
A new instance of User.
-
#private? ⇒ Boolean
def real_account? rescue OpenURI::HTTPError => error response = error.io !response.status.include?(“404” || “Not Found”) end.
- #redisplay ⇒ Object
- #show_five ⇒ Object
- #tweet ⇒ Object
- #tweet_cycle ⇒ Object
Constructor Details
#initialize(user_name) ⇒ User
Returns a new instance of User.
4 5 6 7 8 9 10 |
# 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 |
Instance Attribute Details
#counter ⇒ Object
Returns the value of attribute counter.
2 3 4 |
# File 'lib/twiterator/user.rb', line 2 def counter @counter end |
#display_name ⇒ Object
Returns the value of attribute display_name.
2 3 4 |
# File 'lib/twiterator/user.rb', line 2 def display_name @display_name end |
#doc ⇒ Object
Returns the value of attribute doc.
2 3 4 |
# File 'lib/twiterator/user.rb', line 2 def doc @doc end |
#tweets ⇒ Object
Returns the value of attribute tweets.
2 3 4 |
# File 'lib/twiterator/user.rb', line 2 def tweets @tweets end |
#user_name ⇒ Object
Returns the value of attribute user_name.
2 3 4 |
# File 'lib/twiterator/user.rb', line 2 def user_name @user_name end |
Instance Method Details
#five_more ⇒ Object
48 49 50 51 52 53 |
# File 'lib/twiterator/user.rb', line 48 def five_more this_counter = counter + 5 until counter == this_counter tweet_cycle end end |
#follower_count ⇒ Object
33 34 35 |
# File 'lib/twiterator/user.rb', line 33 def follower_count self.doc.css('.ProfileNav-item--followers a')[0].attr('title') end |
#following_count ⇒ Object
37 38 39 |
# File 'lib/twiterator/user.rb', line 37 def following_count self.doc.css('.ProfileNav-item--following a')[0].attr('title') end |
#get_tweet ⇒ Object
73 74 75 76 77 78 |
# 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? ⇒ Boolean
def real_account?
rescue OpenURI::HTTPError => error
response = error.io
!response.status.include?("404" || "Not Found")
end
29 30 31 |
# File 'lib/twiterator/user.rb', line 29 def private? self.doc.css('.ProtectedTimeline h2').text == "This account's Tweets are protected." || false end |
#redisplay ⇒ Object
55 56 57 58 59 60 |
# 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 ⇒ Object
41 42 43 44 45 46 |
# File 'lib/twiterator/user.rb', line 41 def show_five @counter = 0 until self.counter == 5 tweet_cycle end end |
#tweet ⇒ Object
68 69 70 71 |
# 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 ⇒ Object
62 63 64 65 66 |
# File 'lib/twiterator/user.rb', line 62 def tweet_cycle get_tweet tweet self.counter += 1 end |