class ChildrensBooks::CLI

Public Instance Methods

call() click to toggle source
# File lib/childrens_books/cli.rb, line 4
def call 
    ChildrensBooks::Scraper.scrape
    puts ""
    puts "Welcome to the Children's Books Database!".magenta
    puts ""
    @input = nil
    menu
    while @input != "exit" 
        @input = gets.chomp
        if @input == "1"
            puts "Here are some books 2-4 year olds will love:".green
            books_array = ChildrensBooks::Book.preschoolbooks
            print_books(books_array)
            puts "Enter 'menu' for more options or 'exit' to leave the program.".green
        elsif @input == "2"
            puts "Here are some books 5-7 year olds will love:".green
            books_array = ChildrensBooks::Book.littlekidbooks
            print_books(books_array)
            puts "Enter 'menu' for more options or 'exit' to leave the program.".green
        elsif @input == "3"
            puts "Here are some books 8-9 year olds will love:".green
            books_array = ChildrensBooks::Book.bigkidbooks
            print_books(books_array)
            puts "Enter 'menu' for more options or 'exit' to leave the program.".green
        elsif @input == "4"
            puts "Here are some books 10-12 year olds will love:".green
            books_array = ChildrensBooks::Book.tweenbooks
            print_books(books_array)
            puts "Enter 'menu' for more options or 'exit' to leave the program.".green
        elsif @input == "5"
            puts "Here's a randomly selected book for you to try:".green
            book_obj = ChildrensBooks::Book.all.sample
            print_book(book_obj)
            puts "Enter 'menu' for more options or 'exit' to leave the program.".green
        elsif @input == "menu"
            menu
        elsif @input == "exit"
            break
        else 
            puts "Sorry, you did not select a valid number. Please try again.".red
            puts ""
            menu
        end
    end
    puts "Thanks for visiting. I hope you're headed out to the bookstore!".magenta
end
menu() click to toggle source
print_book(book) click to toggle source
print_books(array) click to toggle source