libri 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 950442ab9569c761f9f0cb86a79c982a3380d0ea73d3e2b3eff462ae11116e76
4
- data.tar.gz: 6cdb49cd65d6044a6cca2b5a4feebf142450ebe6b5d5d1f0fc91dd4b063a4290
3
+ metadata.gz: 8165ef7a5a7120d94748d87b6605b3118175d5f0013cb696ef7ca380f62c853d
4
+ data.tar.gz: 662da9a7efbb5bfa42521b202918fe917739328d29e8fc7c66872cdbc54a0129
5
5
  SHA512:
6
- metadata.gz: d8efc764cde146b8369652762334e617b3821126106f46415f5f6baca005b3e2450251a52298b6da3add660a4f307e1984357643c91c82fb107c3810f22d9a91
7
- data.tar.gz: 2926e272fa819bc909c35e28f48c009631d7d9db791fca01484fbf4975f1d01280da5e0c656dcc97ede4fd81cc9bea3f34dba3562f7c4ea0f98a9340080f7e14
6
+ metadata.gz: '09e526310264ce82aebd1c6eea928a920d376f4c5106bb02fcc8123d1dd6eced64654905be283725c40110b1094192e60ec62c8784ea0443a44912c343b6249c'
7
+ data.tar.gz: f0b9d8ca5cee7f63db2bb9b6b68042339a55c2232d8f7fda8b123fb9eeaf5393c71c8441c1ce66ebaf1740727c8ddbc2cc59e42489183316d4c2b2f343e75700
data/.DS_Store CHANGED
Binary file
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- libri (0.1.0)
4
+ libri (0.1.1)
5
5
  colorize
6
6
  nokogiri (~> 1.8.3)
7
7
 
data/README.md CHANGED
@@ -1,15 +1,14 @@
1
1
  # Libri
2
2
 
3
- This gem is made with the purpose of retrieving detailed information about various book awards shortlist for 2017 2018. All data is scraped from Barnes & Noble's website.
3
+ This gem scrapes the Barnes & Noble website (https://www.barnesandnoble.com/) and provides a CLI for viewing various book awards, the respective shortlisted books, as well as details about each book.
4
4
 
5
5
  ## Installation
6
6
 
7
- You can install this gem via `gem install libri` on your terminal. The `libri` CLI will be installed and you can run `libri` on the terimnal to get a list of notable book awards and a list of shortlisted books available on the B&N website, as well as details and excerpts from the books.
8
-
7
+ You can install this gem via `gem install libri` on your terminal.
9
8
 
10
9
  ## Usage
11
10
 
12
- After installation, run the gem in your CLI by executing `libri`. Make sure to have installed all the required gems beforehand (pry, nokogiri, and open-air), otherwise the command would return error.
11
+ After installation, run the gem in your CLI by executing `libri`. Make sure to have installed all the required gems beforehand (pry, nokogiri, and open-air) by running `bundle install`, otherwise the command would return error.
13
12
 
14
13
  ## Development
15
14
 
data/lib/.DS_Store CHANGED
Binary file
data/lib/libri.rb CHANGED
@@ -6,4 +6,5 @@ require_relative './libri/version'
6
6
  require_relative './libri/cli'
7
7
  require_relative './libri/awards.rb'
8
8
  require_relative './libri/books.rb'
9
- require_relative './libri/book.rb'
9
+ require_relative './libri/book.rb'
10
+ require_relative './libri/quote.rb'
data/lib/libri/book.rb CHANGED
@@ -20,7 +20,7 @@ class Libri::Book
20
20
  # :url => "https://www.barnesandnoble.com" + book.css("a").attribute("href").value
21
21
  # }
22
22
  # },
23
- :availability => book_page.css("button#pdp-marketplace-btn").text.strip,
23
+ :availability => book_page.css("button#pdp-marketplace-btn").text.chomp,
24
24
  :url => book[:url]
25
25
  }
26
26
 
data/lib/libri/cli.rb CHANGED
@@ -1,13 +1,40 @@
1
1
  class Libri::CLI
2
2
  attr_accessor :awards, :name, :book, :url
3
3
 
4
+ LINE = "----------------------------------------------------------"
5
+ SPACE = " "
6
+
4
7
  def call
5
- puts "’Tis some visitor, tapping at my chamber door—".blue
6
- puts "Have you come to indulge in my trophies?".blue
7
- puts "Well, well..".blue
8
+ puts <<~HEREDOC
9
+ . .
10
+ !!!!!!!
11
+ ..'''::::.. . [[[|]]] .
12
+ .::' ``::.. !!!!!!!!|--_--|!!!!!
13
+ '...::' `'':::. [[[[[[[[\\_(X)_/]]]]]
14
+ . . |=| ._/-__-__\\===========/-__\\_
15
+ !!!!!!!!!\\========[ /]]|[[\\ ]=====/
16
+ /_-_-| | |-_--|=| | | ||=|_|_|=||"|==|
17
+ /-__--|_|_|_-_-| |_|_|=||______=||_| =|
18
+ /-----------------------\\===========/-----/
19
+ ^^^\\^^^^^^^^^^^^^^^^^^^^^^[[|]]|[[|]]=====/
20
+ |.' ..==::'"'::==.. '.[ /~~~~~\\ ]]]]]]]
21
+ | .'=[[[|]]|[[|]]]=`._||== = || =\\ ]
22
+ ||= == ||:^s^:|| = == ||=| | | || |=||
23
+ _||_ = =||o---.|| = ==_||_= == =||==_||_
24
+ \\__/= = ||: :||= == \\__/[][][][][]\\__/
25
+ [||]= ==||:___:|| = = [||]\\//\\//\\[||]
26
+ } {---'"'-----'"'- --} {//\\//\\//} {
27
+ ____[==]__________________[==]\\//\\//\\[==]_____
28
+ |`|~~~~|================|~~~~|~~~~~~~~|~~~~||
29
+ jgs|^| ^ |================|^ | ^ ^^ ^ | ^ ||
30
+ HEREDOC
31
+ puts SPACE
8
32
  puts "Welcome to Libri, a chamber full of literary wonders.".blue
9
- puts "Do come inside, this will take a few moments..".blue
33
+ puts "Come freely. This will take a few moments..".blue
34
+ puts "Below are some of the most prized literary awards of our time.".blue
35
+ puts LINE
10
36
  list_awards
37
+ puts LINE
11
38
  leave
12
39
  end
13
40
 
@@ -16,7 +43,9 @@ class Libri::CLI
16
43
  @awards_array.each.with_index(1) { |award, i|
17
44
  puts "#{i}. #{award[:name]}"
18
45
  }
46
+ puts LINE
19
47
  puts "Which award would you like to explore?".blue
48
+ puts LINE
20
49
 
21
50
  menu_awards
22
51
  end
@@ -26,7 +55,9 @@ class Libri::CLI
26
55
  @books_array.each.with_index(1) { |book, i|
27
56
  puts "#{i}. #{book[:title]} #{book[:author]}. #{book[:rating]}"
28
57
  }
58
+ puts LINE
29
59
  puts "Which book would you like to know more about?".blue
60
+ puts LINE
30
61
 
31
62
  menu_books(award)
32
63
  end
@@ -34,9 +65,21 @@ class Libri::CLI
34
65
  def list_details(book)
35
66
  @book_info_hash = Libri::Book.scrape_book(book)
36
67
  @book_info_hash.each { |key, val|
68
+ puts SPACE
37
69
  puts "#{key.upcase}".red
70
+ puts LINE
71
+ puts "#{val}"
72
+ }
73
+ end
74
+
75
+ def random_quote
76
+ @quotes_array = Libri::Quote.scrape_quote
77
+ @random = @quotes_array.sample
78
+ @random.each { |key, val|
79
+ puts SPACE
38
80
  puts "#{val}"
39
81
  }
82
+ puts SPACE
40
83
  end
41
84
 
42
85
  def menu_awards
@@ -45,12 +88,16 @@ class Libri::CLI
45
88
  if input.to_i > 0
46
89
  award = @awards_array[input.to_i - 1]
47
90
  list_books(award)
48
- elsif input == "list awards"
91
+ elsif input == "nevermore"
92
+ puts LINE
93
+ random_quote
94
+ elsif input == "awards"
49
95
  list_awards
50
96
  elsif input == "exit"
51
97
  nil
52
98
  else
53
99
  puts "The raven croaked, 'Please try again.'".red
100
+ puts LINE
54
101
  list_awards
55
102
  end
56
103
  end
@@ -61,24 +108,29 @@ class Libri::CLI
61
108
  if input.to_i > 0
62
109
  book = @books_array[input.to_i - 1]
63
110
  list_details(book)
64
- puts "---------------------------------------------------"
65
- puts "To list the books of the same award again, type list books.".blue
66
- puts "To list all the awards again, type list awards".blue
111
+ puts LINE
112
+ puts " To list the books of the same award again, type books.".blue
113
+ puts " To list all the awards again, type awards".blue
114
+ puts LINE
67
115
  menu_books(award)
68
- elsif input == "list books"
116
+ elsif input == "nevermore"
117
+ puts LINE
118
+ random_quote
119
+ elsif input == "books"
69
120
  list_books(award)
70
- elsif input == "list awards"
121
+ elsif input == "awards"
71
122
  list_awards
72
123
  elsif input == "exit"
73
124
  nil
74
125
  else
75
126
  puts "The raven croaked, 'Please try again.'".red
127
+ puts LINE
76
128
  list_books(award)
77
129
  end
78
130
  end
79
131
 
80
132
  def leave
81
- puts "Nevermore!".blue
133
+ puts "Farewell!".blue
82
134
  end
83
135
 
84
136
  end
@@ -0,0 +1,22 @@
1
+ class Libri::Quote
2
+ attr_accessor :quote
3
+
4
+ def self.scrape_quote
5
+ html = "https://www.goodreads.com/quotes/tag/books"
6
+ quotes_page = Nokogiri::HTML(open(html))
7
+ quote_section = quotes_page.css("div.quote")
8
+
9
+ quotes_array = []
10
+ quote_hash = {}
11
+
12
+ quote_section.each { |quote|
13
+ quote_hash = {
14
+ :quote => quote.css("div.quoteText").first.text.scan(/(“.+”)/).join(""),
15
+ :author => quote.css("div.quoteText a").first.text
16
+ }
17
+
18
+ quotes_array << quote_hash
19
+ }
20
+ quotes_array
21
+ end
22
+ end
data/lib/libri/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Libri
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - jouissances
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-24 00:00:00.000000000 Z
11
+ date: 2018-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -124,6 +124,7 @@ files:
124
124
  - lib/libri/book.rb
125
125
  - lib/libri/books.rb
126
126
  - lib/libri/cli.rb
127
+ - lib/libri/quote.rb
127
128
  - lib/libri/version.rb
128
129
  - libri.gemspec
129
130
  - spec.md