best_books 0.1.0 → 0.2.0
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/best_books-0.1.0.gem +0 -0
- data/best_books.gemspec +1 -0
- data/lib/best_books/book.rb +6 -9
- data/lib/best_books/cli.rb +28 -5
- data/lib/best_books/decade.rb +23 -5
- data/lib/best_books/scraper.rb +44 -0
- data/lib/best_books/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c1f7dda016ffd899da0672ecbf72b78be19fdeb
|
4
|
+
data.tar.gz: 3eb8dfca09cfbfc63eafcbb90df43494046076a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fcdf78d3980bdd3ebfc0f0831d6ba86875967065a6890ba133a6aad6acc0801600f0de192d3c99ea3c32b0d6a96c3baedc1334ebe2d8e4831878a555e0c1689
|
7
|
+
data.tar.gz: 8ec22541e05302863e65d97ceeda3983624b522dac01b9945f8d650d6663b363d7e72347da8ad3eaca09520101b47101f9cc74f92ac5e7fc1dd56b97719b706d
|
Binary file
|
data/best_books.gemspec
CHANGED
@@ -9,6 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["thelucasmoore"]
|
10
10
|
spec.email = ["lucasedwardmoore@gmail.com"]
|
11
11
|
|
12
|
+
spec.description = "A CLI archive of the best books of each century."
|
12
13
|
spec.summary = "A CLI archive of the best books of every century."
|
13
14
|
spec.homepage = "https://github.com/TheLucasMoore/best-books-of-the-century.git"
|
14
15
|
spec.license = "MIT"
|
data/lib/best_books/book.rb
CHANGED
@@ -2,8 +2,9 @@ class BestBooks::Book
|
|
2
2
|
|
3
3
|
attr_accessor :ranking, :title, :link, :author, :rating, :description, :decade
|
4
4
|
|
5
|
+
@@all = []
|
6
|
+
|
5
7
|
def initialize
|
6
|
-
@@all
|
7
8
|
@ranking = ranking
|
8
9
|
@title = title
|
9
10
|
@link = link
|
@@ -11,6 +12,7 @@ class BestBooks::Book
|
|
11
12
|
@rating = rating
|
12
13
|
@description = description
|
13
14
|
@decade = decade
|
15
|
+
@@all << self
|
14
16
|
end
|
15
17
|
|
16
18
|
def self.scrape(link)
|
@@ -22,12 +24,12 @@ class BestBooks::Book
|
|
22
24
|
libro = BestBooks::Book.new
|
23
25
|
libro.ranking = this.css("td.number").text
|
24
26
|
libro.title = this.css("a.bookTitle span").text
|
25
|
-
libro.link = this.css("a.bookTitle").attr("href")
|
27
|
+
libro.link = this.css("a.bookTitle").attr("href").value
|
26
28
|
libro.author = this.css(".authorName span").text
|
27
29
|
libro.rating = this.css(".minirating").text.strip
|
30
|
+
finder = Nokogiri::HTML(open("https://www.goodreads.com" + libro.link))
|
31
|
+
libro.description = finder.css("#description span").text
|
28
32
|
#libro.decade = BestBooks::Decade.name
|
29
|
-
## descrip = Nokogiri::HTML(open("https://www.goodreads.com" + libro.link))
|
30
|
-
## libro.description = descrip.css("div.description span").text
|
31
33
|
libro
|
32
34
|
@top10books.push(libro)
|
33
35
|
else
|
@@ -41,9 +43,4 @@ class BestBooks::Book
|
|
41
43
|
@@all
|
42
44
|
end
|
43
45
|
|
44
|
-
def description
|
45
|
-
#@@all.each do |descrip|
|
46
|
-
#
|
47
|
-
#end
|
48
|
-
end
|
49
46
|
end
|
data/lib/best_books/cli.rb
CHANGED
@@ -12,20 +12,43 @@ class BestBooks::CLI
|
|
12
12
|
@decade
|
13
13
|
end
|
14
14
|
|
15
|
+
def topten(input)
|
16
|
+
#This takes over a minute to load and that's gotta change.
|
17
|
+
BestBooks::Decade.top10(input.to_i)
|
18
|
+
end
|
19
|
+
|
20
|
+
def book_descriptions(input, book_input)
|
21
|
+
BestBooks::Decade.description(input, book_input.to_i)
|
22
|
+
end
|
23
|
+
|
15
24
|
def menu
|
16
25
|
input = nil
|
26
|
+
puts "Enter the number of the century for which you want to see the Top Books!"
|
27
|
+
puts "Type 'list' to see the centuries again, or type 'exit'"
|
17
28
|
while input != "exit"
|
18
|
-
puts "Enter the number of the century for which you want to see the Top Books!"
|
19
|
-
puts "Type 'list' to see the centuries again, or type 'exit'"
|
20
29
|
input = gets.strip.downcase
|
21
30
|
if input.to_i > 0
|
22
|
-
puts "Here are the top 10 books of the"
|
31
|
+
puts "Loading.... Here are the top 10 books of the"
|
23
32
|
puts @decade[input.to_i-1].name
|
24
|
-
|
33
|
+
topten(input)
|
34
|
+
|
35
|
+
book_input = ""
|
36
|
+
while book_input != "exit"
|
37
|
+
puts "Type the number of the book to read the description, rating and more information."
|
38
|
+
book_input = gets.strip.downcase
|
39
|
+
if book_input.to_i > 0
|
40
|
+
book_descriptions(input, book_input)
|
41
|
+
puts "For information on another book, enter its number."
|
42
|
+
puts "To see the top ten books for this decade, type 'top ten'"
|
43
|
+
elsif book_input == "top ten"
|
44
|
+
topten(input)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
25
48
|
elsif input == "list"
|
26
49
|
list_decades
|
27
50
|
else
|
28
|
-
puts "Not sure what you mean by that. Try 'list' or 'exit'
|
51
|
+
puts "Not sure what you mean by that. Try 'list' or 'exit'"
|
29
52
|
end
|
30
53
|
end
|
31
54
|
end
|
data/lib/best_books/decade.rb
CHANGED
@@ -32,8 +32,16 @@ class BestBooks::Decade
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
def self.save
|
36
|
+
@@all << self
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.all
|
40
|
+
@@all
|
41
|
+
end
|
42
|
+
|
43
|
+
|
35
44
|
def self.books
|
36
|
-
#binding.pry
|
37
45
|
@@all.each do |geturl|
|
38
46
|
bookscraper = BestBooks::Book.scrape(geturl.url)
|
39
47
|
top10 = []
|
@@ -43,10 +51,6 @@ class BestBooks::Decade
|
|
43
51
|
@@all
|
44
52
|
end
|
45
53
|
|
46
|
-
def self.all
|
47
|
-
@@all
|
48
|
-
end
|
49
|
-
|
50
54
|
def self.top10(input)
|
51
55
|
BestBooks::Decade.books
|
52
56
|
iterate = @@all[input]
|
@@ -55,5 +59,19 @@ class BestBooks::Decade
|
|
55
59
|
end
|
56
60
|
end
|
57
61
|
|
62
|
+
def self.description(input, book_input)
|
63
|
+
#BestBooks::Decade.books
|
64
|
+
iterate = @@all[input.to_i]
|
65
|
+
iterate.top10.each do |book|
|
66
|
+
if book.ranking.to_i == book_input
|
67
|
+
puts "#{book.ranking} #{book.title} by #{book.author}"
|
68
|
+
puts "Rated #{book.rating}"
|
69
|
+
puts "#{book.description}"
|
70
|
+
else
|
71
|
+
puts " "
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
58
76
|
end
|
59
77
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class Scraper < ActiveRecord::Base
|
2
|
+
|
3
|
+
def self.decades
|
4
|
+
decades = Nokogiri::HTML(open("https://www.goodreads.com/list/show/7"))
|
5
|
+
decades.css("div.mediumText a").each do |scrape|
|
6
|
+
if scrape.text.include?("Century")
|
7
|
+
decade = Decade.new
|
8
|
+
decade.name = scrape.text.strip.gsub("Best Books of the ", "")
|
9
|
+
decade.url = scrape.attr("href")
|
10
|
+
decade.save
|
11
|
+
else
|
12
|
+
scrape
|
13
|
+
end
|
14
|
+
end
|
15
|
+
Decades.all
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def self.books(link)
|
20
|
+
self.scrape(link)
|
21
|
+
books = Nokogiri::HTML(open(link))
|
22
|
+
@top10books = []
|
23
|
+
|
24
|
+
books.search("tr").each do |this|
|
25
|
+
if this.css("td.number").text.to_i <= 10
|
26
|
+
libro = BestBooks::Book.new
|
27
|
+
libro.ranking = this.css("td.number").text
|
28
|
+
libro.title = this.css("a.bookTitle span").text
|
29
|
+
libro.link = this.css("a.bookTitle").attr("href").value
|
30
|
+
libro.author = this.css(".authorName span").text
|
31
|
+
libro.rating = this.css(".minirating").text.strip
|
32
|
+
finder = Nokogiri::HTML(open("https://www.goodreads.com" + libro.link))
|
33
|
+
libro.description = finder.css("#description span").text
|
34
|
+
#libro.decade = BestBooks::Decade.name
|
35
|
+
libro
|
36
|
+
@top10books.push(libro)
|
37
|
+
else
|
38
|
+
this
|
39
|
+
end
|
40
|
+
end
|
41
|
+
return @top10books
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/best_books/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: best_books
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thelucasmoore
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description: A CLI archive of the best books of each century.
|
84
84
|
email:
|
85
85
|
- lucasedwardmoore@gmail.com
|
86
86
|
executables: []
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- LICENSE.txt
|
96
96
|
- README.md
|
97
97
|
- Rakefile
|
98
|
+
- best_books-0.1.0.gem
|
98
99
|
- best_books.gemspec
|
99
100
|
- bin/best-books
|
100
101
|
- bin/console
|
@@ -103,6 +104,7 @@ files:
|
|
103
104
|
- lib/best_books/book.rb
|
104
105
|
- lib/best_books/cli.rb
|
105
106
|
- lib/best_books/decade.rb
|
107
|
+
- lib/best_books/scraper.rb
|
106
108
|
- lib/best_books/version.rb
|
107
109
|
homepage: https://github.com/TheLucasMoore/best-books-of-the-century.git
|
108
110
|
licenses:
|