lib/libri/cli.rb in libri-0.2.1 vs lib/libri/cli.rb in libri-0.2.2
- old
+ new
@@ -1,116 +1,133 @@
class Libri::CLI
- attr_accessor :awards, :name, :book, :url
+ attr_accessor :award, :awards_array, :books_array, :book_info_hash, :quotes_array, :title_by_author
+
LINE = "----------------------------------------------------------"
SPACE = " "
+ STRING = <<-EOS
+ . .
+ !!!!!!!
+ ..'''::::.. . [[[|]]] .
+ .::' ``::.. !!!!!!!!|--_--|!!!!!
+ '...::' `'':::. [[[[[[[[\\_(X)_/]]]]]
+ . . |=| ._/-__-__\\===========/-__\\_
+ !!!!!!!!!\\========[ /]]|[[\\ ]=====/
+ /_-_-| | |-_--|=| | | ||=|_|_|=||"|==|
+ /-__--|_|_|_-_-| |_|_|=||______=||_| =|
+ /-----------------------\\===========/-----/
+ ^^^\\^^^^^^^^^^^^^^^^^^^^^^[[|]]|[[|]]=====/
+ |.' ..==::'"'::==.. '.[ /~~~~~\\ ]]]]]]]
+ | .'=[[[|]]|[[|]]]=`._||== = || =\\ ]
+ ||= == ||:^s^:|| = == ||=| | | || |=||
+ _||_ = =||o---.|| = ==_||_= == =||==_||_
+ \\__/= = ||: :||= == \\__/[][][][][]\\__/
+ [||]= ==||:___:|| = = [||]\\//\\//\\[||]
+ } {---'"'-----'"'- --} {//\\//\\//} {
+ ____[==]__________________[==]\\//\\//\\[==]_____
+ |`|~~~~|================|~~~~|~~~~~~~~|~~~~||
+ jgs|^| ^ |================|^ | ^ ^^ ^ | ^ ||
+ EOS
def call
- puts <<~HEREDOC
- . .
- !!!!!!!
- ..'''::::.. . [[[|]]] .
- .::' ``::.. !!!!!!!!|--_--|!!!!!
-'...::' `'':::. [[[[[[[[\\_(X)_/]]]]]
- . . |=| ._/-__-__\\===========/-__\\_
- !!!!!!!!!\\========[ /]]|[[\\ ]=====/
- /_-_-| | |-_--|=| | | ||=|_|_|=||"|==|
- /-__--|_|_|_-_-| |_|_|=||______=||_| =|
- /-----------------------\\===========/-----/
- ^^^\\^^^^^^^^^^^^^^^^^^^^^^[[|]]|[[|]]=====/
- |.' ..==::'"'::==.. '.[ /~~~~~\\ ]]]]]]]
- | .'=[[[|]]|[[|]]]=`._||== = || =\\ ]
- ||= == ||:^s^:|| = == ||=| | | || |=||
- _||_ = =||o---.|| = ==_||_= == =||==_||_
- \\__/= = ||: :||= == \\__/[][][][][]\\__/
- [||]= ==||:___:|| = = [||]\\//\\//\\[||]
- } {---'"'-----'"'- --} {//\\//\\//} {
- ____[==]__________________[==]\\//\\//\\[==]_____
- |`|~~~~|================|~~~~|~~~~~~~~|~~~~||
- jgs|^| ^ |================|^ | ^ ^^ ^ | ^ ||
- HEREDOC
+ puts STRING
puts SPACE
puts "Welcome to Libri, a chamber full of literary wonders.".blue
- puts "Come freely. This will take a few moments..".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
+ def make_awards
+ @awards_array = Scraper.scrape_barnes_noble
+ Libri::Awards.create_from_collection(awards_array)
+ end
+
def list_awards
- @awards_array = Libri::Awards.all
- @awards_array.each.with_index(1) { |award, i|
- puts "#{i}. #{award[:name]}"
+ 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
+ def make_books(award)
+ @books_array = Scraper.scrape_award(award)
+ Libri::Books.create_from_collection(books_array)
+ end
+
def list_books(award)
- @books_array = Libri::Books.scrape_award(award)
- @books_array.each.with_index(1) { |book, i|
- puts "#{i}. #{book[:title]} #{book[:author]}. #{book[:rating]}"
+ 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
def list_details(book)
- @book_info_hash = Libri::Book.scrape_book(book)
+ @book_info_hash = Scraper.scrape_book(book)
+
@book_info_hash.each { |key, val|
puts SPACE
- puts "#{key.upcase}".red
+ puts "#{key}".upcase.red
puts LINE
puts "#{val}"
- }
+ }
end
def random_quote
- @quotes_array = Libri::Quote.scrape_quote
- @random = @quotes_array.sample
- @random.each { |key, val|
+ @quotes_array = Scraper.scrape_quote
+ Libri::Quote.create_from_collection(quotes_array)
+
+ random = @quotes_array.sample
+ random.each { |key, val|
puts SPACE
puts "#{val}"
}
puts SPACE
end
def menu_awards
input = STDIN.gets.strip.downcase
- if input.to_i > 0
+ if input.to_i.between?(1,15)
award = @awards_array[input.to_i - 1]
+ Libri::Books.all.clear
+ make_books(award)
list_books(award)
- elsif input == "nevermore"
- puts LINE
- random_quote
elsif input == "awards"
list_awards
elsif input == "exit"
nil
+ elsif input == "nevermore"
+ puts LINE
+ random_quote
else
puts "The raven croaked, 'Please try again.'".red
puts LINE
list_awards
end
end
def menu_books(award)
input = STDIN.gets.strip.downcase
- if input.to_i > 0
+ if input.to_i.between?(1,20)
book = @books_array[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 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)
elsif input == "nevermore"
puts LINE
\ No newline at end of file