Class: NYTBestsellers::CLI
- Inherits:
-
Object
- Object
- NYTBestsellers::CLI
- Defined in:
- lib/nytimes/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #display_book_info(response, book_input) ⇒ Object
- #display_genres ⇒ Object
- #genre_books(response) ⇒ Object
- #genre_count ⇒ Object
- #run ⇒ Object
Instance Method Details
#call ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/nytimes/cli.rb', line 3 def call NYTBestsellers::Scraper.make_genres NYTBestsellers::Scraper.make_books puts "" puts "Welcome to the New York Times Bestsellers List".blue.bold run end |
#display_book_info(response, book_input) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/nytimes/cli.rb', line 83 def display_book_info(response, book_input) genre = NYTBestsellers::Genre.find_by_num(response) genre.books.each_with_index do |book, index| if book_input.to_i == index+1 puts "****----#{book.title}----****".blue.bold puts "" puts "Weeks On Bestseller:".bold + " #{book.wol}" puts "Author:".bold + " #{book.}" puts "Publisher:".bold + " #{book.publisher}" puts "Genre:".bold + " #{book.genre.name}" puts "" puts "---------Summary---------".bold puts "#{book.summary}" puts "" input = "" while input != "exit" puts "Type" + " 'back'".red + "," + " 'menu',".red + " or" + " 'exit'".red + "." input = gets.strip puts "" if input == "back" genre_books(response) elsif input == "menu" run puts "" elsif input == "exit" puts "Goodbye!~".bold.red puts "" exit end #second if end end #first if end #each end |
#display_genres ⇒ Object
40 41 42 43 44 |
# File 'lib/nytimes/cli.rb', line 40 def display_genres NYTBestsellers::Genre.all.each_with_index do |genre, index| puts "#{index+1} - #{genre.name}" end end |
#genre_books(response) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/nytimes/cli.rb', line 46 def genre_books(response) genre = NYTBestsellers::Genre.find_by_num(response) puts "" puts "****----#{genre.name.upcase}----****".blue.bold puts "" puts " Rank^ Title" puts " ----- -----" genre.books.each_with_index do |book, index| rank = " #{index+1} " rank << " " if (0..8).include?(index) title = " #{book.title}" puts rank + title end puts "" puts "(^refers to the current position on the bestseller's list)" puts "" book_input = "" while book_input != "exit" puts "Select a book by rank number to get more info." puts "You may type" + " 'back'".red + " to return to the categories or " + "'exit'".red + " to close the CLI." book_input = gets.strip puts "" if (1..genre.books.count).include?(book_input.to_i) display_book_info(response, book_input) elsif book_input == "back" run elsif book_input == "exit" puts "Goodbye!~".bold.red puts "" exit end end end |
#genre_count ⇒ Object
36 37 38 |
# File 'lib/nytimes/cli.rb', line 36 def genre_count NYTBestsellers::Genre.all.count end |
#run ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/nytimes/cli.rb', line 11 def run puts "-------------------" puts "" puts "NYT Bestsellers - Week of #{NYTBestsellers::Scraper.get_date}".bold.blue puts "(Lists are published early online.)".bold.blue puts "" puts "Here are the categories:" puts "" display_genres puts "" response = "" while response != "exit" puts "Select a category by number or type " + "'exit'".red + " to close the CLI." response = gets.strip if (1..genre_count).to_a.include?(response.to_i) genre_books(response.to_i) elsif response == "exit" puts "Goodbye!~".bold.red puts "" exit end end end |