nyt-bestsellers 0.1.3 → 0.1.4

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: 6a62b5da961841947fa45b6b7802932193d0e5b3b757eecb5cb9f79778395e65
4
- data.tar.gz: 370cb594e99fce26fe4d9fc23e3a9c3c4855539203c384dfa67e7fab2337df68
3
+ metadata.gz: 5fe7fe081125f8c59f398fd15e60f686df204d97180ee0e627731baae27444df
4
+ data.tar.gz: 9c675e9c24485fdc720d5d0337552ff47a1f48ce9bafbebfab59ee940453e622
5
5
  SHA512:
6
- metadata.gz: 1d3e40274785e3428548193980372760a0cb51431cddd48446185e1b67bca58faa794ca88bb707f78ea5de0bd1278aa10b8e0cd38e2497d27ccc2e7401930662
7
- data.tar.gz: f692331ff871353e2f742a661df88ea263008c34e226807fbfb00a58cf8bf351ec33dcc4430484e8009d85a0c7d4055231364915f4b2549f38799d6a3c278bf0
6
+ metadata.gz: b791e8d0b56af005a790196beee89326ce59dd70133d3afa5285cae83bb3446366f86b1acf5627e9e5aac4dd5d1c098d046aa394af851190f2ab31306b4a2ad8
7
+ data.tar.gz: fc880be8603a47393860b2377f91ccfdf65408a94b7c8e2d17ae6ebe0142f8946b94ad468f7b1edf83c0a1fd94ef21d4133313990572b1259300e5a463e0c709
data/bin/nyt-bestsellers CHANGED
@@ -1,5 +1,5 @@
1
- #!/usr/bin/env ruby
2
- require 'bundler/setup'
3
- require 'nyt_bestsellers'
4
-
1
+ #!/usr/bin/env ruby
2
+ require 'bundler/setup'
3
+ require 'nyt_bestsellers'
4
+
5
5
  NYTBestsellers::CLI.new.call
@@ -1,12 +1,12 @@
1
- require 'pry'
2
- require 'nokogiri'
3
- require 'open-uri'
4
- require 'colorize'
5
- require 'mechanize'
6
- require 'scraper'
7
- require 'book'
8
- require 'cli'
9
- require 'genre'
10
-
11
- module NYTBestsellers
12
- end
1
+ require 'pry'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ require 'colorize'
5
+ require 'mechanize'
6
+ require 'scraper'
7
+ require 'book'
8
+ require 'cli'
9
+ require 'genre'
10
+
11
+ module NYTBestsellers
12
+ end
data/lib/nytimes/book.rb CHANGED
@@ -1,29 +1,29 @@
1
- module NYTBestsellers
2
- class Book
3
- attr_accessor :genre, :title, :author, :publisher, :wol, :summary
4
- @@all = []
5
-
6
- def initialize(hash = {})
7
- hash.each do |key, value|
8
- self.send("#{key}=", value)
9
- end
10
- @genre = NYTBestsellers::Genre.find_by_name(hash[:genre])
11
- if !wol.empty? || !summary.empty?
12
- @genre.books << self
13
- @@all << self
14
- end
15
- end
16
-
17
- def self.all
18
- @@all
19
- end
20
-
21
- def self.find_by_title(name)
22
- self.all.find do |book|
23
- if name == book.title
24
- book
25
- end
26
- end
27
- end
28
- end
1
+ module NYTBestsellers
2
+ class Book
3
+ attr_accessor :genre, :title, :author, :publisher, :wol, :summary
4
+ @@all = []
5
+
6
+ def initialize(hash = {})
7
+ hash.each do |key, value|
8
+ self.send("#{key}=", value)
9
+ end
10
+ @genre = NYTBestsellers::Genre.find_by_name(hash[:genre])
11
+ if !wol.empty? || !summary.empty?
12
+ @genre.books << self
13
+ @@all << self
14
+ end
15
+ end
16
+
17
+ def self.all
18
+ @@all
19
+ end
20
+
21
+ def self.find_by_title(name)
22
+ self.all.find do |book|
23
+ if name == book.title
24
+ book
25
+ end
26
+ end
27
+ end
28
+ end
29
29
  end
data/lib/nytimes/cli.rb CHANGED
@@ -1,119 +1,119 @@
1
- module NYTBestsellers
2
- class CLI
3
- def call
4
- NYTBestsellers::Scraper.make_genres
5
- NYTBestsellers::Scraper.make_books
6
- puts ""
7
- puts "Welcome to the New York Times Bestsellers List".blue.bold
8
- run
9
- end
10
-
11
- def run
12
- puts "-------------------"
13
- puts ""
14
- puts "NYT Bestsellers - Week of #{NYTBestsellers::Scraper.get_date}".bold.blue
15
- puts "(Lists are published early online.)".bold.blue
16
- puts ""
17
- puts "Here are the categories:"
18
- puts ""
19
- display_genres
20
- puts ""
21
-
22
- response = ""
23
- while response != "exit"
24
- puts "Select a category by number or type " + "'exit'".light_red + " to close the CLI."
25
- response = gets.strip
26
- if (1..genre_count).to_a.include?(response.to_i)
27
- genre_books(response.to_i)
28
- elsif response == "exit"
29
- puts "Goodbye!~".bold.red
30
- puts ""
31
- exit
32
- end
33
- end
34
- end
35
-
36
- def genre_count
37
- NYTBestsellers::Genre.all.count
38
- end
39
-
40
- def display_genres
41
- NYTBestsellers::Genre.all.each_with_index do |genre, index|
42
- puts "#{index+1} - #{genre.name}"
43
- end
44
- end
45
-
46
- def genre_books(response)
47
- genre = NYTBestsellers::Genre.find_by_num(response)
48
- puts ""
49
- puts "****----#{genre.name.upcase}----****".blue.bold
50
- puts ""
51
- puts " Rank^ Title"
52
- puts " ----- -----"
53
- genre.books.each_with_index do |book, index|
54
- rank = " #{index+1} "
55
- rank << " " if (0..8).include?(index)
56
-
57
- title = " #{book.title}"
58
- puts rank + title
59
- end
60
-
61
- puts ""
62
- puts "(^refers to the current position on the bestseller's list)"
63
- puts ""
64
-
65
- book_input = ""
66
- while book_input != "exit"
67
- puts "Select a book by rank number to get more info."
68
- puts "You may type" + " 'back'".light_red + " to return to the categories or " + "'exit'".light_red + " to close the CLI."
69
- book_input = gets.strip
70
- puts ""
71
- if (1..genre.books.count).include?(book_input.to_i)
72
- display_book_info(response, book_input)
73
- elsif book_input == "back"
74
- run
75
- elsif book_input == "exit"
76
- puts "Goodbye!~".bold.red
77
- puts ""
78
- exit
79
- end
80
- end
81
- end
82
-
83
- def display_book_info(response, book_input)
84
- genre = NYTBestsellers::Genre.find_by_num(response)
85
-
86
- genre.books.each_with_index do |book, index|
87
- if book_input.to_i == index+1
88
- puts "****----#{book.title}----****".blue.bold
89
- puts ""
90
- puts "Weeks On Bestseller:".bold + " #{book.wol}"
91
- puts "Author:".bold + " #{book.author}"
92
- puts "Publisher:".bold + " #{book.publisher}"
93
- puts "Genre:".bold + " #{book.genre.name}"
94
- puts ""
95
- puts "---------Summary---------".bold
96
- puts "#{book.summary}"
97
- puts ""
98
-
99
- input = ""
100
- while input != "exit"
101
- puts "Type" + " 'back'".light_red + "," + " 'menu',".light_red + " or" + " 'exit'".light_red + "."
102
- input = gets.strip
103
- puts ""
104
- if input == "back"
105
- genre_books(response)
106
- elsif input == "menu"
107
- run
108
- puts ""
109
- elsif input == "exit"
110
- puts "Goodbye!~".bold.red
111
- puts ""
112
- exit
113
- end #second if
114
- end
115
- end #first if
116
- end #each
117
- end
118
- end
1
+ module NYTBestsellers
2
+ class CLI
3
+ def call
4
+ NYTBestsellers::Scraper.make_genres
5
+ NYTBestsellers::Scraper.make_books
6
+ puts ""
7
+ puts "Welcome to the New York Times Bestsellers List".blue.bold
8
+ run
9
+ end
10
+
11
+ def run
12
+ puts "-------------------"
13
+ puts ""
14
+ puts "NYT Bestsellers - Week of #{NYTBestsellers::Scraper.get_date}".bold.blue
15
+ puts "(Lists are published early online.)".bold.blue
16
+ puts ""
17
+ puts "Here are the categories:"
18
+ puts ""
19
+ display_genres
20
+ puts ""
21
+
22
+ response = ""
23
+ while response != "exit"
24
+ puts "Select a category by number or type " + "'exit'".red + " to close the CLI."
25
+ response = gets.strip
26
+ if (1..genre_count).to_a.include?(response.to_i)
27
+ genre_books(response.to_i)
28
+ elsif response == "exit"
29
+ puts "Goodbye!~".bold.red
30
+ puts ""
31
+ exit
32
+ end
33
+ end
34
+ end
35
+
36
+ def genre_count
37
+ NYTBestsellers::Genre.all.count
38
+ end
39
+
40
+ def display_genres
41
+ NYTBestsellers::Genre.all.each_with_index do |genre, index|
42
+ puts "#{index+1} - #{genre.name}"
43
+ end
44
+ end
45
+
46
+ def genre_books(response)
47
+ genre = NYTBestsellers::Genre.find_by_num(response)
48
+ puts ""
49
+ puts "****----#{genre.name.upcase}----****".blue.bold
50
+ puts ""
51
+ puts " Rank^ Title"
52
+ puts " ----- -----"
53
+ genre.books.each_with_index do |book, index|
54
+ rank = " #{index+1} "
55
+ rank << " " if (0..8).include?(index)
56
+
57
+ title = " #{book.title}"
58
+ puts rank + title
59
+ end
60
+
61
+ puts ""
62
+ puts "(^refers to the current position on the bestseller's list)"
63
+ puts ""
64
+
65
+ book_input = ""
66
+ while book_input != "exit"
67
+ puts "Select a book by rank number to get more info."
68
+ puts "You may type" + " 'back'".red + " to return to the categories or " + "'exit'".red + " to close the CLI."
69
+ book_input = gets.strip
70
+ puts ""
71
+ if (1..genre.books.count).include?(book_input.to_i)
72
+ display_book_info(response, book_input)
73
+ elsif book_input == "back"
74
+ run
75
+ elsif book_input == "exit"
76
+ puts "Goodbye!~".bold.red
77
+ puts ""
78
+ exit
79
+ end
80
+ end
81
+ end
82
+
83
+ def display_book_info(response, book_input)
84
+ genre = NYTBestsellers::Genre.find_by_num(response)
85
+
86
+ genre.books.each_with_index do |book, index|
87
+ if book_input.to_i == index+1
88
+ puts "****----#{book.title}----****".blue.bold
89
+ puts ""
90
+ puts "Weeks On Bestseller:".bold + " #{book.wol}"
91
+ puts "Author:".bold + " #{book.author}"
92
+ puts "Publisher:".bold + " #{book.publisher}"
93
+ puts "Genre:".bold + " #{book.genre.name}"
94
+ puts ""
95
+ puts "---------Summary---------".bold
96
+ puts "#{book.summary}"
97
+ puts ""
98
+
99
+ input = ""
100
+ while input != "exit"
101
+ puts "Type" + " 'back'".red + "," + " 'menu',".red + " or" + " 'exit'".red + "."
102
+ input = gets.strip
103
+ puts ""
104
+ if input == "back"
105
+ genre_books(response)
106
+ elsif input == "menu"
107
+ run
108
+ puts ""
109
+ elsif input == "exit"
110
+ puts "Goodbye!~".bold.red
111
+ puts ""
112
+ exit
113
+ end #second if
114
+ end
115
+ end #first if
116
+ end #each
117
+ end
118
+ end
119
119
  end
data/lib/nytimes/genre.rb CHANGED
@@ -1,30 +1,30 @@
1
- module NYTBestsellers
2
- class Genre
3
- attr_accessor :name, :url
4
- @@all = []
5
-
6
- def initialize(hash = {})
7
- hash.each do |key, value|
8
- self.send("#{key}=", value)
9
- end
10
- @@all << self
11
- @books = []
12
- end
13
-
14
- def self.all
15
- @@all
16
- end
17
-
18
- def books
19
- @books
20
- end
21
-
22
- def self.find_by_name(genre_name)
23
- self.all.find {|x| x.name == genre_name}
24
- end
25
-
26
- def self.find_by_num(num_input)
27
- self.all[num_input.to_i-1]
28
- end
29
- end
1
+ module NYTBestsellers
2
+ class Genre
3
+ attr_accessor :name, :url
4
+ @@all = []
5
+
6
+ def initialize(hash = {})
7
+ hash.each do |key, value|
8
+ self.send("#{key}=", value)
9
+ end
10
+ @@all << self
11
+ @books = []
12
+ end
13
+
14
+ def self.all
15
+ @@all
16
+ end
17
+
18
+ def books
19
+ @books
20
+ end
21
+
22
+ def self.find_by_name(genre_name)
23
+ self.all.find {|x| x.name == genre_name}
24
+ end
25
+
26
+ def self.find_by_num(num_input)
27
+ self.all[num_input.to_i-1]
28
+ end
29
+ end
30
30
  end
@@ -1,47 +1,47 @@
1
- module NYTBestsellers
2
- class Scraper
3
- def self.get_page
4
- @@page ||= Mechanize.new.get("http://www.nytimes.com/books/best-sellers/")
5
- end
6
-
7
- def self.make_genres
8
- get_page.css("section h2").each do |category|
9
- NYTBestsellers::Genre.new({
10
- name: category.css("a").text.strip,
11
- url: "http://www.nytimes.com#{category.css("a").attr("href").text}"
12
- })
13
- end
14
- end
15
-
16
- def self.get_genre_pages
17
- agent = Mechanize.new
18
- NYTBestsellers::Genre.all.collect do |genre|
19
- page = agent.get("#{genre.url}")
20
- end
21
- end
22
-
23
- def self.make_books
24
- get_genre_pages.each do |page|
25
- book_genre = page.css("section h2")[0].text
26
- books = page.css("ol")[0].css("li article a")
27
-
28
- books.each do |book|
29
- if book.css("p")[1] != nil && book.css("p")[1].attribute("itemprop").value == "author"
30
- NYTBestsellers::Book.new({
31
- genre: book_genre,
32
- title: book.css("h3").text.split.collect(&:capitalize).join(" "),
33
- author: book.css("p")[1].text.split.delete_if{|x| x == "by"}.join(" "),
34
- publisher: book.css("p")[2].text,
35
- wol: book.css("p")[0].text,
36
- summary: book.css("p")[3].text
37
- })
38
- end
39
- end
40
- end
41
- end
42
-
43
- def self.get_date
44
- get_page.css("div.date-range").text.strip
45
- end
46
- end
47
- end
1
+ module NYTBestsellers
2
+ class Scraper
3
+ def self.get_page
4
+ @@page ||= Mechanize.new.get("http://www.nytimes.com/books/best-sellers/")
5
+ end
6
+
7
+ def self.make_genres
8
+ get_page.css("section h2").each do |category|
9
+ NYTBestsellers::Genre.new({
10
+ name: category.css("a").text.strip,
11
+ url: "http://www.nytimes.com#{category.css("a").attr("href").text}"
12
+ })
13
+ end
14
+ end
15
+
16
+ def self.get_genre_pages
17
+ agent = Mechanize.new
18
+ NYTBestsellers::Genre.all.collect do |genre|
19
+ page = agent.get("#{genre.url}")
20
+ end
21
+ end
22
+
23
+ def self.make_books
24
+ get_genre_pages.each do |page|
25
+ book_genre = page.css("section h2")[0].text
26
+ books = page.css("ol")[0].css("li article a")
27
+
28
+ books.each do |book|
29
+ if book.css("p")[1] != nil && book.css("p")[1].attribute("itemprop").value == "author"
30
+ NYTBestsellers::Book.new({
31
+ genre: book_genre,
32
+ title: book.css("h3").text.split.collect(&:capitalize).join(" "),
33
+ author: book.css("p")[1].text.split.delete_if{|x| x == "by"}.join(" "),
34
+ publisher: book.css("p")[2].text,
35
+ wol: book.css("p")[0].text,
36
+ summary: book.css("p")[3].text
37
+ })
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def self.get_date
44
+ get_page.css("time").text.strip
45
+ end
46
+ end
47
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nyt-bestsellers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amy Back
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-14 00:00:00.000000000 Z
11
+ date: 2022-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.11'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '10.0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -148,8 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
134
  - !ruby/object:Gem::Version
149
135
  version: '0'
150
136
  requirements: []
151
- rubyforge_project:
152
- rubygems_version: 2.7.6
137
+ rubygems_version: 3.1.2
153
138
  signing_key:
154
139
  specification_version: 4
155
140
  summary: Lists books by genre from the NYT Bestsellers List