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 +4 -4
- data/.DS_Store +0 -0
- data/Gemfile.lock +1 -1
- data/README.md +3 -4
- data/lib/.DS_Store +0 -0
- data/lib/libri.rb +2 -1
- data/lib/libri/book.rb +1 -1
- data/lib/libri/cli.rb +63 -11
- data/lib/libri/quote.rb +22 -0
- data/lib/libri/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8165ef7a5a7120d94748d87b6605b3118175d5f0013cb696ef7ca380f62c853d
|
4
|
+
data.tar.gz: 662da9a7efbb5bfa42521b202918fe917739328d29e8fc7c66872cdbc54a0129
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09e526310264ce82aebd1c6eea928a920d376f4c5106bb02fcc8123d1dd6eced64654905be283725c40110b1094192e60ec62c8784ea0443a44912c343b6249c'
|
7
|
+
data.tar.gz: f0b9d8ca5cee7f63db2bb9b6b68042339a55c2232d8f7fda8b123fb9eeaf5393c71c8441c1ce66ebaf1740727c8ddbc2cc59e42489183316d4c2b2f343e75700
|
data/.DS_Store
CHANGED
Binary file
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
# Libri
|
2
2
|
|
3
|
-
This gem
|
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.
|
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)
|
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
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.
|
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
|
6
|
-
|
7
|
-
|
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 "
|
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 == "
|
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
|
66
|
-
puts "To list all the awards again, type
|
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 == "
|
116
|
+
elsif input == "nevermore"
|
117
|
+
puts LINE
|
118
|
+
random_quote
|
119
|
+
elsif input == "books"
|
69
120
|
list_books(award)
|
70
|
-
elsif input == "
|
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 "
|
133
|
+
puts "Farewell!".blue
|
82
134
|
end
|
83
135
|
|
84
136
|
end
|
data/lib/libri/quote.rb
ADDED
@@ -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
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.
|
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-
|
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
|