Class: CLI
- Inherits:
-
Object
- Object
- CLI
- Defined in:
- lib/nyt_bestsellers_cli_gem/CLI.rb
Instance Method Summary collapse
- #book_details ⇒ Object
- #buy_book ⇒ Object
- #call ⇒ Object
- #pick_category ⇒ Object
- #return_to_pick_category ⇒ Object
-
#spaces ⇒ Object
HELPER METHODS.
Instance Method Details
#book_details ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/nyt_bestsellers_cli_gem/CLI.rb', line 33 def book_details spaces puts "Please type in the title of the book to see its summary.".upcase puts "Type back to review other categories.".upcase input = gets.strip.upcase if Book.find_by_title(input) != nil if Book.find_by_title(input).summary != "" spaces puts Book.find_by_title(input).summary.upcase buy_book else puts "Sorry, this book does not have a summary provided.".upcase buy_book end else return_to_pick_category end end |
#buy_book ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/nyt_bestsellers_cli_gem/CLI.rb', line 67 def buy_book puts "Would you like to buy this book? (y/n)".upcase input = gets.strip.downcase if input == "y" system("open https://www.nytimes.com/books/best-sellers/") return_to_pick_category else return_to_pick_category end end |
#call ⇒ Object
3 4 5 6 |
# File 'lib/nyt_bestsellers_cli_gem/CLI.rb', line 3 def call Scraper.new.scrape pick_category end |
#pick_category ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/nyt_bestsellers_cli_gem/CLI.rb', line 8 def pick_category spaces puts "WELCOME TO THE NEW YORK TIMES BESTSELLER LIST!" spaces Category.all.each.with_index(1) do |category_instance, i| puts "#{i}. #{category_instance.name}".upcase end spaces puts "Please choose the number of the category you wish to inspect:".upcase input = gets.strip if input == "exit" spaces puts "Thank you for stopping by!".upcase exit elsif input.to_i > 0 && input.to_i < 6 Category.all[input.to_i - 1].books.each do |book| spaces puts "#{book.title} - #{book.}".upcase end book_details else return_to_pick_category end end |
#return_to_pick_category ⇒ Object
61 62 63 64 65 |
# File 'lib/nyt_bestsellers_cli_gem/CLI.rb', line 61 def return_to_pick_category spaces puts "Type exit at anytime to exit.".upcase pick_category end |
#spaces ⇒ Object
HELPER METHODS
56 57 58 59 |
# File 'lib/nyt_bestsellers_cli_gem/CLI.rb', line 56 def spaces puts "" puts "" end |