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
print_book(book)
click to toggle source
# File lib/childrens_books/cli.rb, line 78 def print_book(book) puts "" puts "Title: #{book.title}" puts "Author: #{book.author}" puts "Description: #{book.description}" puts "Release Year: #{book.year}" puts "Age: #{book.age}" puts "" end
print_books(array)
click to toggle source
# File lib/childrens_books/cli.rb, line 66 def print_books(array) array.each do |book| puts "" puts "Title: #{book.title}" puts "Author: #{book.author}" puts "Description: #{book.description}" puts "Release Year: #{book.year}" puts "Age: #{book.age}" puts "" end end