Class: User

Inherits:
Object
  • Object
show all
Defined in:
lib/twiterator/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#counterObject

Returns the value of attribute counter.



2
3
4
# File 'lib/twiterator/user.rb', line 2

def counter
  @counter
end

#display_nameObject

Returns the value of attribute display_name.



2
3
4
# File 'lib/twiterator/user.rb', line 2

def display_name
  @display_name
end

#docObject

Returns the value of attribute doc.



2
3
4
# File 'lib/twiterator/user.rb', line 2

def doc
  @doc
end

#tweetsObject

Returns the value of attribute tweets.



2
3
4
# File 'lib/twiterator/user.rb', line 2

def tweets
  @tweets
end

#user_nameObject

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_moreObject



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_countObject



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_countObject



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_tweetObject



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

Returns:

  • (Boolean)


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

#redisplayObject



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_fiveObject



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

#tweetObject



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_cycleObject



62
63
64
65
66
# File 'lib/twiterator/user.rb', line 62

def tweet_cycle
  get_tweet
  tweet
  self.counter += 1
end