Class: TwiteratorCLI
- Inherits:
-
Object
- Object
- TwiteratorCLI
- Defined in:
- lib/twiterator/twiterator-cli.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#tweet ⇒ Object
Returns the value of attribute tweet.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #display_possible ⇒ Object
- #display_profile ⇒ Object
- #display_tweet(index) ⇒ Object
- #give_options ⇒ Object
-
#initialize ⇒ TwiteratorCLI
constructor
A new instance of TwiteratorCLI.
- #new_user_menu ⇒ Object
- #not_verified(user) ⇒ Object
- #search_possible(user) ⇒ Object
- #set_replies ⇒ Object
- #show_replies ⇒ Object
- #tweet_options ⇒ Object
-
#tweet_response ⇒ Object
def options_response answer = gets.strip.upcase if answer == “MORE” self.user.five_more give_options elsif answer == “NEW” new_user_menu elsif answer.to_i > 0 display_tweet(answer.to_i) end end.
Constructor Details
#initialize ⇒ TwiteratorCLI
Returns a new instance of TwiteratorCLI.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/twiterator/twiterator-cli.rb', line 5 def initialize puts " " puts "************ | TWITERATOR #{Twiterator::VERSION} | ************" puts " " puts "\nHi there! I'm Twiterator, a Ruby cli scraper for" puts "the popular social networking site, Twitter." puts "You can type a twitter handle (or search for one!), and I will" puts "display that user's basic info along with their most" puts "recent tweets. From there, you'll be able to dive into" puts "each tweet and play around until your thirst for" puts "knowledge of the twitterverse is quenched." end |
Instance Attribute Details
#doc ⇒ Object
Returns the value of attribute doc.
3 4 5 |
# File 'lib/twiterator/twiterator-cli.rb', line 3 def doc @doc end |
#tweet ⇒ Object
Returns the value of attribute tweet.
3 4 5 |
# File 'lib/twiterator/twiterator-cli.rb', line 3 def tweet @tweet end |
#user ⇒ Object
Returns the value of attribute user.
3 4 5 |
# File 'lib/twiterator/twiterator-cli.rb', line 3 def user @user end |
Instance Method Details
#display_possible ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/twiterator/twiterator-cli.rb', line 44 def display_possible counter = 0 puts " " puts "Hmm, that's not a twitter handle, but here are some users you might have been looking for:" puts "-" until (self.doc.css('.js-action-profile-name')[counter] == nil) || (counter == 4) do display_name = self.doc.css('.js-action-profile-name')[counter].text.strip user_name = self.doc.css('.ProfileCard-screenname')[counter].text.strip bio = self.doc.css('.ProfileCard-bio')[counter].text.strip puts "For #{display_name.upcase}, type '#{user_name}'" puts bio puts " " counter +=1 end end |
#display_profile ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/twiterator/twiterator-cli.rb', line 62 def display_profile puts " " puts "#{self.user.display_name.upcase} - @#{self.user.user_name}" puts "#{self.user.following_count}" puts "#{self.user.follower_count}" puts " " if self.user.private? puts "Out of respect for this user's privacy, I'm not willing to display their tweets at this time." else self.user.show_five end end |
#display_tweet(index) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/twiterator/twiterator-cli.rb', line 85 def display_tweet(index) tweet_number = index-1 @tweet = self.user.tweets[tweet_number] puts "-------------" puts "On #{tweet.date}, at approximately #{tweet.time} #{tweet.user_name} wrote:" puts "'#{tweet.content}'" puts "-----" puts "#{tweet.reply_count} people replied to this tweet." puts "#{tweet.retweets} people retweeted." puts "#{tweet.likes} people liked it." puts "--" end |
#give_options ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/twiterator/twiterator-cli.rb', line 77 def puts "-To see more of #{self.user.display_name}'s tweets, type 'more.'" puts "-To check out a different user's tweets, type 'new'" puts "-To learn more about a tweet, simply type the number of the tweet you'd like to learn about." #options_response tweet_response end |
#new_user_menu ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/twiterator/twiterator-cli.rb', line 19 def puts "\nPlease enter a twitter handle or search for the user you're thinking of." puts "(ex. 'kanyewest' or 'President of Mexico')" user = gets.chomp if not_verified(user) search_possible(user) display_possible elsif @user = User.new(user) end display_profile end |
#not_verified(user) ⇒ Object
33 34 35 36 |
# File 'lib/twiterator/twiterator-cli.rb', line 33 def not_verified(user) new_verify = Verification.new(user) new_verify.verify == false end |
#search_possible(user) ⇒ Object
38 39 40 41 42 |
# File 'lib/twiterator/twiterator-cli.rb', line 38 def search_possible(user) formatted_user = user.gsub(' ', '%20') html = open("https://twitter.com/search?f=users&q=#{formatted_user}&src=typd") @doc = Nokogiri::HTML(html) end |
#set_replies ⇒ Object
107 108 109 |
# File 'lib/twiterator/twiterator-cli.rb', line 107 def set_replies self.tweet.set_replies end |
#show_replies ⇒ Object
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/twiterator/twiterator-cli.rb', line 143 def show_replies self.tweet.replies.each_with_index do |reply, index| puts "#{index+1}. #{reply.content}\n" end puts "---" puts "To redisplay #{self.user.display_name}'s tweets, type 'back'" puts "OR" puts "To search for a new tweeter, type 'new'" tweet_response end |
#tweet_options ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/twiterator/twiterator-cli.rb', line 99 def puts "To view some of the replies to this tweet, type 'replies'" puts "To see more tweets from #{self.user.display_name}, type 'more'" puts "To check out a different user's tweets, type 'new'" set_replies tweet_response end |
#tweet_response ⇒ Object
def options_response
answer = gets.strip.upcase
if answer == "MORE"
self.user.five_more
elsif answer == "NEW"
elsif answer.to_i > 0
display_tweet(answer.to_i)
end
end
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/twiterator/twiterator-cli.rb', line 123 def tweet_response answer = gets.strip.upcase if answer == "REPLIES" && self.tweet != nil show_replies elsif answer == "MORE" self.user.five_more elsif answer == "BACK" self.user.redisplay elsif answer == "NEW" elsif answer.to_i > 0 display_tweet(answer.to_i) else puts "Uh oh!! I don't know what you're trying to say! Sorry about that." end end |