Class: DayBooks::CLI
- Inherits:
-
Object
- Object
- DayBooks::CLI
- Defined in:
- lib/CLI.rb
Instance Attribute Summary collapse
-
#chosen_book ⇒ Object
Returns the value of attribute chosen_book.
Instance Method Summary collapse
- #call ⇒ Object
- #choose_book ⇒ Object
- #return_description(chosen_book) ⇒ Object
- #start_over? ⇒ Boolean
Instance Attribute Details
#chosen_book ⇒ Object
Returns the value of attribute chosen_book.
5 6 7 |
# File 'lib/CLI.rb', line 5 def chosen_book @chosen_book end |
Instance Method Details
#call ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/CLI.rb', line 7 def call puts "Welcome to the book library of best selling romance author, Sylvia Day." puts "Would you like to see a list of the books she has written? Please type 'yes' or 'no'." while true input = gets.chomp.downcase if input == "yes" || input == "y" choose_book break elsif input == "no" || input == "n" puts "Thank you for using Sylvia Day's library. Goodbye." break else puts "Invalid input. Please try again." end end end |
#choose_book ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/CLI.rb', line 25 def choose_book DayBooks::Scraper.get_book_info books = DayBooks::Scraper.books_array books.each {|book| DayBooks::Book.create(book[:title], book[:book_url])} DayBooks::Book.all.sort_by! {|book| book.title} DayBooks::Book.all.each {|book| puts "#{book.title}"} puts "Please type the title of the book you'd like to learn more about!" while true chosen_book = gets.chomp.downcase if DayBooks::Book.downcase_all_titles.include?(chosen_book) return_description(chosen_book) start_over? break else puts "Invalid input. Please try again." end end end |
#return_description(chosen_book) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/CLI.rb', line 45 def return_description(chosen_book) book_url = "" DayBooks::Book.all.each do |book| if book.title.downcase == chosen_book book_url = book.book_url end end description = DayBooks::Scraper.get_description(book_url) if description == "" puts "Sorry this book has no description." else puts description end end |
#start_over? ⇒ Boolean
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/CLI.rb', line 60 def start_over? puts "Would you like to see the list of books again? Please type 'yes' or 'no'." while true input = gets.chomp.downcase if input == "yes" || input == "y" DayBooks::Scraper.empty_books_array DayBooks::Book.empty_all choose_book break elsif input == "no" || input == "n" puts "Thank you for using Sylvia Day's library. Goodbye." break else puts "Invalid input. Please try again." end end end |