class CLI
Public Instance Methods
book_details()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/nyt_bestsellers_cli_gem/CLI.rb, line 3 def call Scraper.new.scrape pick_category end
pick_category()
click to toggle source
# 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.author}".upcase end book_details else return_to_pick_category end end
return_to_pick_category()
click to toggle source
# 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()
click to toggle source
HELPER METHODS
# File lib/nyt_bestsellers_cli_gem/CLI.rb, line 56 def spaces puts "" puts "" end