Class: BestReads::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/best_reads/cli.rb

Instance Method Summary collapse

Instance Method Details

#callObject



3
4
5
# File 'lib/best_reads/cli.rb', line 3

def call
  start_menu
end

#start_menuObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/best_reads/cli.rb', line 7

def start_menu
 puts "Welcome to Best Reads!"

 #First menu loop: lists_menu
 loop do
   puts "Please choose one of our Best-Of Lists"
   #Scraping best of lists of books and initializing list objects
   best_of_lists = BestReads::Scraper.scrape_best_of_lists
   BestReads::List.create_and_display_from_collection(best_of_lists)
   puts "Please enter a number between 1 and #{best_of_lists.size} or exit to quit".colorize(:color => :red)
   list_number = gets.strip.downcase
   if(list_number.to_i.between?(1,best_of_lists.size))
     list_url = BestReads::List.find_by_index(list_number.to_i).url
     #Second menu loop: books_menu
     loop do
       best_of_books = BestReads::Scraper.scrape_books_by_list(list_url.to_s)
       BestReads::Book.create_and_display_from_collection(best_of_books)

       puts "Press 0 to return to the previous menu, exit to quit or any key to refresh your page".colorize(:color => :red)
       books_menu_input = gets.strip.downcase
       break if books_menu_input =="0"
       return if books_menu_input =="exit"
     end
    end
    break if list_number == "exit"
  end
end