Class: NYTFiction::CLI
- Inherits:
-
Object
- Object
- NYTFiction::CLI
- Defined in:
- lib/nyt_fiction/cli.rb
Instance Method Summary collapse
Instance Method Details
#call ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/nyt_fiction/cli.rb', line 3 def call puts "----------------------------" puts "This week's New York Times'" puts "Print & E-Book Fiction Best Sellers: \n\n" NYTFiction::Scraper.scrape_books get_books list_books end |
#get_books ⇒ Object
13 14 15 |
# File 'lib/nyt_fiction/cli.rb', line 13 def get_books @books = NYTFiction::Book.all end |
#list_books ⇒ Object
17 18 19 20 21 22 |
# File 'lib/nyt_fiction/cli.rb', line 17 def list_books @books.each.with_index(1) do |b, i| puts "#{i}. #{b.title} #{b.}" end puts "----------------------------" end |
#menu ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/nyt_fiction/cli.rb', line 24 def puts "\nEnter the number of the book (1-15)" print "that you'd like to learn more about: " input = nil while input != "exit" input = gets.chomp if input.to_i.between?(1, 15) b = @books[input.to_i - 1] puts "\nRank: #{input} (#{b.freshness})" puts "#{b.title} #{b.} (#{b.publisher})" puts "#{b.description}" print "\nPlease enter another book number, list to see list again, or exit: " elsif input == "list" list_books elsif input == "exit" puts "Thanks! Check back next week." exit else print "Please enter a number 1-15, list, or exit: " end end end |