class Libri::CLI

Constants

LINE

Attributes

award[RW]
awards_array[RW]
book_info_hash[RW]
books_array[RW]
quotes_array[RW]
title_by_author[RW]

Public Instance Methods

call() click to toggle source
# File lib/libri/cli.rb, line 7
def call
    puts "Welcome to Libri.".blue
    puts "I'm the Raven, your guide in this chamber full of literary wonders.".blue
    puts "Below are some of the most prized literary awards of our time.".blue
    puts "Come freely. This will take a few moments...".blue
    puts LINE
    make_awards
    list_awards
    puts LINE
    leave
end
leave() click to toggle source
# File lib/libri/cli.rb, line 149
def leave
    puts "Farewell!".blue
end
list_awards() click to toggle source
# File lib/libri/cli.rb, line 23
def list_awards
    Libri::Awards.all.each.with_index(1) { |award, i|
        puts "#{i}. #{award.name}"
    }
    puts LINE
    puts "Which award would you like to explore?".blue
    puts LINE

    menu_awards
end
list_books(award) click to toggle source
# File lib/libri/cli.rb, line 38
def list_books(award)
    Libri::Books.all.each.with_index(1) { |book, i|
        puts "#{i}. #{book.title} #{book.author}"
    }
    puts LINE
    puts "Which book would you like to know more about?".blue
    puts LINE

    menu_books(award)
    
end
list_details(book) click to toggle source
# File lib/libri/cli.rb, line 50
def list_details(book)
    info = Libri::Scraper.new.scrape_book(book)

    puts 
    puts "Title by Author".upcase.red
    puts LINE
    puts "#{info.title_by_author}"
    puts
    puts "Blurbs and Plot".upcase.red
    puts LINE
    puts "#{info.blurbs_and_plot}"
    puts
    puts "About the Author".upcase.red
    puts LINE
    puts "#{info.about_author}"
    puts 
    puts "Availability".upcase.red
    puts LINE
    puts "#{info.availability}"
    puts        
    puts "URL".upcase.red
    puts LINE
    puts "#{info.url}"
    puts 

    if !info.excerpt.nil?
        puts "An excerpt of this book is available. Would you like to read it? (Yn)".blue
        input = STDIN.gets.strip.downcase
        if input == "y"
            puts
            puts "Excerpt".upcase.red
            puts LINE
            puts "#{info.excerpt.slice(1..1000)}..."
            puts
        else
            nil
        end
    end
end
make_awards() click to toggle source
# File lib/libri/cli.rb, line 19
def make_awards
    Libri::Scraper.new.scrape_barnes_noble
end
make_books(award) click to toggle source
# File lib/libri/cli.rb, line 34
def make_books(award)
    Libri::Scraper.new.scrape_award(award)
end
menu_awards() click to toggle source
menu_books(award) click to toggle source
random_quote() click to toggle source
# File lib/libri/cli.rb, line 90
def random_quote
    quote = Libri::Scraper.new.scrape_quote.sample

    puts
    puts "#{quote.quote}"
    puts 
    puts "#{quote.author}"
    puts
end