lib/libri/cli.rb in libri-0.2.5 vs lib/libri/cli.rb in libri-0.2.6
- old
+ new
@@ -15,12 +15,11 @@
puts LINE
leave
end
def make_awards
- @awards_array = Libri::Scraper.new.scrape_barnes_noble
- Libri::Awards.create_from_collection(awards_array)
+ Libri::Scraper.new.scrape_barnes_noble
end
def list_awards
Libri::Awards.all.each.with_index(1) { |award, i|
puts "#{i}. #{award.name}"
@@ -31,12 +30,11 @@
menu_awards
end
def make_books(award)
- @books_array = Libri::Scraper.new.scrape_award(award)
- Libri::Books.create_from_collection(books_array)
+ Libri::Scraper.new.scrape_award(award)
end
def list_books(award)
Libri::Books.all.each.with_index(1) { |book, i|
puts "#{i}. #{book.title} #{book.author}"
@@ -48,37 +46,64 @@
menu_books(award)
end
def list_details(book)
- @book_info_hash = Libri::Scraper.new.scrape_book(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
- @book_info_hash.each { |key, val|
- puts
- puts "#{key}".upcase.red
- puts LINE
- puts "#{val}"
- }
+ if !info.excerpt.nil?
+ puts "An excerpt of this book is available. Would you like to read it? (Yn)"
+ input = STDIN.gets.strip.downcase
+ if input == "y"
+ puts
+ puts "Excerpt".upcase.red
+ puts LINE
+ puts "#{info.excerpt.slice(1..1000)}..."
+ puts
+ else
+ menu_books(award)
+ end
+ end
end
def random_quote
- @quotes_array = Libri::Scraper.new.scrape_quote
- Libri::Quote.create_from_collection(quotes_array)
+ quote = Libri::Scraper.new.scrape_quote.sample
- random = @quotes_array.sample
- random.each { |key, val|
- puts
- puts "#{val}"
- }
+ puts
+ puts "#{quote.quote}"
puts
+ puts "#{quote.author}"
+ puts
end
def menu_awards
input = STDIN.gets.strip.downcase
if input.to_i.between?(1,Libri::Awards.all.size)
- award = @awards_array[input.to_i - 1]
+ award = Libri::Awards.all[input.to_i - 1]
Libri::Books.all.clear
make_books(award)
list_books(award)
elsif input == "awards"
list_awards
@@ -95,17 +120,17 @@
end
def menu_books(award)
input = STDIN.gets.strip.downcase
- if input.to_i.between?(1,20)
- book = @books_array[input.to_i - 1]
+ if input.to_i.between?(1,Libri::Books.all.size)
+ book = Libri::Books.all[input.to_i - 1]
list_details(book)
puts LINE
puts "To list the books of the same award again, type books".blue
puts "To list all the awards again, type awards".blue
puts LINE
- menu_books(award)
+ menu_books(award)
elsif input == "nevermore"
puts LINE
random_quote
elsif input == "books"
list_books(award)
\ No newline at end of file