Class: Libri::CLI
- Inherits:
-
Object
- Object
- Libri::CLI
- Defined in:
- lib/libri/cli.rb
Constant Summary collapse
- LINE =
"----------------------------------------------------------"
Instance Attribute Summary collapse
-
#award ⇒ Object
Returns the value of attribute award.
-
#awards_array ⇒ Object
Returns the value of attribute awards_array.
-
#book_info_hash ⇒ Object
Returns the value of attribute book_info_hash.
-
#books_array ⇒ Object
Returns the value of attribute books_array.
-
#quotes_array ⇒ Object
Returns the value of attribute quotes_array.
-
#title_by_author ⇒ Object
Returns the value of attribute title_by_author.
Instance Method Summary collapse
- #call ⇒ Object
- #leave ⇒ Object
- #list_awards ⇒ Object
- #list_books(award) ⇒ Object
- #list_details(book) ⇒ Object
- #make_awards ⇒ Object
- #make_books(award) ⇒ Object
- #menu_awards ⇒ Object
- #menu_books(award) ⇒ Object
- #random_quote ⇒ Object
Instance Attribute Details
#award ⇒ Object
Returns the value of attribute award.
3 4 5 |
# File 'lib/libri/cli.rb', line 3 def award @award end |
#awards_array ⇒ Object
Returns the value of attribute awards_array.
3 4 5 |
# File 'lib/libri/cli.rb', line 3 def awards_array @awards_array end |
#book_info_hash ⇒ Object
Returns the value of attribute book_info_hash.
3 4 5 |
# File 'lib/libri/cli.rb', line 3 def book_info_hash @book_info_hash end |
#books_array ⇒ Object
Returns the value of attribute books_array.
3 4 5 |
# File 'lib/libri/cli.rb', line 3 def books_array @books_array end |
#quotes_array ⇒ Object
Returns the value of attribute quotes_array.
3 4 5 |
# File 'lib/libri/cli.rb', line 3 def quotes_array @quotes_array end |
#title_by_author ⇒ Object
Returns the value of attribute title_by_author.
3 4 5 |
# File 'lib/libri/cli.rb', line 3 def @title_by_author end |
Instance Method Details
#call ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# 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 ⇒ Object
149 150 151 |
# File 'lib/libri/cli.rb', line 149 def leave puts "Farewell!".blue end |
#list_awards ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# 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 end |
#list_books(award) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# 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.}" } puts LINE puts "Which book would you like to know more about?".blue puts LINE (award) end |
#list_details(book) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# 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.}" 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.}" 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 ⇒ Object
19 20 21 |
# File 'lib/libri/cli.rb', line 19 def make_awards Libri::Scraper.new. end |
#make_books(award) ⇒ Object
34 35 36 |
# File 'lib/libri/cli.rb', line 34 def make_books(award) Libri::Scraper.new.scrape_award(award) end |
#menu_awards ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/libri/cli.rb', line 100 def input = STDIN.gets.strip.downcase if input.to_i.between?(1,Libri::Awards.all.size) award = Libri::Awards.all[input.to_i - 1] Libri::Books.all.clear make_books(award) list_books(award) 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 |
#menu_books(award) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/libri/cli.rb', line 122 def (award) input = STDIN.gets.strip.downcase 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 (award) elsif input == "nevermore" puts LINE random_quote elsif input == "books" list_books(award) elsif input == "awards" list_awards elsif input == "exit" nil else puts "The raven croaked, 'Please try again.'".red puts LINE list_books(award) end end |
#random_quote ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/libri/cli.rb', line 90 def random_quote quote = Libri::Scraper.new.scrape_quote.sample puts puts "#{quote.quote}" puts puts "#{quote.}" puts end |