class BestBooks::CLI
Public Instance Methods
call()
click to toggle source
# File lib/best_books/cli.rb, line 3 def call BestBooks::Categories.get_bookcards puts "Welcome to the Goodreads Best Books of 2018!" puts "" list_categories puts "" menu end
choose_category()
click to toggle source
# File lib/best_books/cli.rb, line 41 def choose_category puts "" puts "Choose the category by entering its number." puts "" input = gets.strip.to_i max_value = BestBooks::Categories.all.length if input.between?(1,max_value) category = BestBooks::Categories.all[input-1] puts "" display_book_info(category) else puts "I'm sorry, I didn't understand." list_categories choose_category end end
display_book_info(category)
click to toggle source
# File lib/best_books/cli.rb, line 58 def display_book_info(category) BestBooks::Scraper.scrape_book_details(category) puts "Here are the title, author, and a brief description of the winner:" puts "" puts "Title:" puts category.book_title puts "" puts "Author:" puts category.author puts "" puts "Description:" puts category.description puts "" second_menu end
list_categories()
click to toggle source
# File lib/best_books/cli.rb, line 12 def list_categories puts "" puts "Below is the list of categories:" BestBooks::Categories.all.each.with_index(1) do |category, index| puts "#{index}. #{category.name}" end end
scrape_book_info(chosen_category)
click to toggle source
# File lib/best_books/cli.rb, line 74 def scrape_book_info(chosen_category) category = BestBooks::Categories.all[chosen_category] url = category.url BestBooks::Scraper.scrape_book_details(url) end