Class: Toogle::CLI
- Inherits:
-
Object
- Object
- Toogle::CLI
- Defined in:
- lib/toogle/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #creation ⇒ Object
- #get_and_show_data ⇒ Object
- #goodbye ⇒ Object
- #perform_new_search? ⇒ Boolean
- #scraper_gets_user_info ⇒ Object
- #show_title_intro ⇒ Object
Instance Method Details
#call ⇒ Object
3 4 5 6 7 8 |
# File 'lib/toogle/cli.rb', line 3 def call show_title_intro creation get_and_show_data perform_new_search? end |
#creation ⇒ Object
43 44 45 |
# File 'lib/toogle/cli.rb', line 43 def creation Toogle::Query.create end |
#get_and_show_data ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/toogle/cli.rb', line 47 def get_and_show_data Toogle::Query.all.each do |ele| puts "\n#{ele.title.green}" puts "_".yellow * ele.title.length puts "\n#{ele.link.blue}" puts ele.description.red puts end end |
#goodbye ⇒ Object
70 71 72 73 74 |
# File 'lib/toogle/cli.rb', line 70 def goodbye puts "\nSee you soon!" puts exit! end |
#perform_new_search? ⇒ Boolean
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/toogle/cli.rb', line 57 def perform_new_search? while true puts "\nWould you like to enter a new search?(Y/n)" input = gets.chomp.downcase if input == 'y' creation get_and_show_data elsif input == 'n' || input != 'y' goodbye end end end |
#scraper_gets_user_info ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/toogle/cli.rb', line 17 def scraper_gets_user_info scraper = Toogle::Scraper.new while true puts "\nEnter your".red + " search term/s".green print "\n> ".green query = gets.chomp.to_s.downcase if query == "" puts "\nSorry, you must enter a valid search, or if you wish to exit type 'exit' or press Control C" elsif query == 'exit' goodbye else print "\nHow many pages would you like for you search, choose between 1 and 5? " pages = gets.chomp.to_i if !(1..5).include?(pages) puts "\nSorry, you can only search within the first 5 pages" elsif pages.to_s == 'exit' goodbye else break end end end puts "\nLoading".yellow + " search".green + " results".blue + " ...".red scraper.query_data(query, pages) end |