nyt-bestsellers 0.0.2 → 0.0.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
  SHA1:
3
- metadata.gz: ada07f12703db76eac60fe562660c08c1e1af02d
4
- data.tar.gz: 68d508bebc12879e83c6a499dead3c3a6dedb60f
3
+ metadata.gz: 364b65e29799c494484045f477d1fe2094d0f172
4
+ data.tar.gz: 4be1d126014b763428f274def89093b436dc2af1
5
5
  SHA512:
6
- metadata.gz: e85bab7360689bc3a5e6de860632ba750e3883ee49abce441e8ca3ce70fdf11c7b67d37b63717d83957cacde5691660395eb2945e1ff5713449e07eec23ff71a
7
- data.tar.gz: 5e4a13554a4c1cc1b1349593fb9a0b7a3acd55ca5d1d50d19e12a34db78a3f28f2dcc7676c76823908fa254e833659e97268c3b3463e23200cb7fcbffca9b72a
6
+ metadata.gz: ad9c40794d6af2f71e94c51d4945b6c263090c965308f776a6e4d1edddea0f09ca9e3bf01146ae4a831cf63e69dfe6de5a36221ec739ce78e88eafafe86879d8
7
+ data.tar.gz: 951595ba0534a305b7480ff8c9bb67fdee9073e6a13670b71d0e2c6ea7e5f8c4921bfba8651c47f6600e55f5a6fe79e418988894d1fc455cf628821bf414f612
data/bin/nyt-bestsellers CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require_relative '../lib/nyt_bestsellers.rb'
4
4
 
5
- NYTBestsellers::CLI.new.call
5
+ CLI.new.call
data/lib/nytimes/book.rb CHANGED
@@ -1,11 +1,11 @@
1
- class NYTBestsellers::Book
1
+ class Book
2
2
 
3
3
  attr_accessor :genre, :title, :author, :publisher, :wol, :summary
4
4
 
5
5
  @@all = []
6
6
 
7
7
  def initialize(genre=nil, title=nil, author=nil, publisher=nil, wol=nil, summary=nil)
8
- @genre = NYTBestsellers::Genre.find_by_name(genre)
8
+ @genre = Genre.find_by_name(genre)
9
9
  @genre.books << self if !wol.empty? || !summary.empty?
10
10
  @title = title
11
11
  @author = author
data/lib/nytimes/cli.rb CHANGED
@@ -1,8 +1,8 @@
1
- class NYTBestsellers::CLI
1
+ class CLI
2
2
 
3
3
  def call
4
- NYTBestsellers::Scraper.make_genres
5
- NYTBestsellers::Scraper.make_books
4
+ Scraper.make_genres
5
+ Scraper.make_books
6
6
  puts ""
7
7
  puts "Welcome to the New York Times Bestsellers List".blue.bold
8
8
  run
@@ -11,7 +11,7 @@ class NYTBestsellers::CLI
11
11
  def run
12
12
  puts "-------------------"
13
13
  puts ""
14
- puts "NYT Bestsellers - Week of #{NYTBestsellers::Scraper.get_date}".bold.blue
14
+ puts "NYT Bestsellers - Week of #{Scraper.get_date}".bold.blue
15
15
  puts "(Lists are published early online.)".bold.blue
16
16
  puts ""
17
17
  puts "Here are the categories:"
@@ -34,17 +34,17 @@ class NYTBestsellers::CLI
34
34
  end
35
35
 
36
36
  def genre_count
37
- NYTBestsellers::Genre.all.count
37
+ Genre.all.count
38
38
  end
39
39
 
40
40
  def display_genres
41
- NYTBestsellers::Genre.all.each_with_index do |genre, index|
41
+ Genre.all.each_with_index do |genre, index|
42
42
  puts "#{index+1} - #{genre.name}"
43
43
  end
44
44
  end
45
45
 
46
46
  def genre_books(response)
47
- genre = NYTBestsellers::Genre.find_by_num(response)
47
+ genre = Genre.find_by_num(response)
48
48
  puts ""
49
49
  puts "****----#{genre.name.upcase}----****".blue.bold
50
50
  puts ""
@@ -81,7 +81,7 @@ class NYTBestsellers::CLI
81
81
  end
82
82
 
83
83
  def display_book_info(response, book_input)
84
- genre = NYTBestsellers::Genre.find_by_num(response)
84
+ genre = Genre.find_by_num(response)
85
85
 
86
86
  genre.books.each_with_index do |book, index|
87
87
  if book_input.to_i == index+1
@@ -95,25 +95,24 @@ class NYTBestsellers::CLI
95
95
  puts "---------Summary---------".bold
96
96
  puts "#{book.summary}"
97
97
  puts ""
98
- puts "Type" + " 'back'".light_red + "," + " 'menu',".light_red + " or" + " 'exit'".light_red + "."
99
- puts ""
100
98
 
101
- input = gets.strip
102
- puts ""
103
- if input == "back"
104
- genre_books(response)
105
- elsif input == "exit"
106
- puts "Goodbye!~".bold.red
99
+ input = ""
100
+ while input != "exit"
101
+ puts "Type" + " 'back'".light_red + "," + " 'menu',".light_red + " or" + " 'exit'".light_red + "."
102
+ input = gets.strip
107
103
  puts ""
108
- exit
109
- elsif input == "menu"
110
- run
111
- puts ""
112
- else
113
- display_book_info(response, book_input)
114
- end #second if
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
115
  end #first if
116
116
  end #each
117
117
  end
118
-
119
118
  end
data/lib/nytimes/genre.rb CHANGED
@@ -1,4 +1,4 @@
1
- class NYTBestsellers::Genre
1
+ class Genre
2
2
 
3
3
  attr_accessor :name, :url
4
4
 
@@ -1,4 +1,4 @@
1
- class NYTBestsellers::Scraper
1
+ class Scraper
2
2
 
3
3
  def self.get_page
4
4
  agent = Mechanize.new
@@ -11,7 +11,7 @@ class NYTBestsellers::Scraper
11
11
 
12
12
  def self.make_genres
13
13
  scrape_genres.each do |category|
14
- NYTBestsellers::Genre.new(
14
+ Genre.new(
15
15
  category.css("a.subcategory-heading-link").text.strip,
16
16
  "http://www.nytimes.com#{category.css("a").attr("href").text}"
17
17
  )
@@ -20,7 +20,7 @@ class NYTBestsellers::Scraper
20
20
 
21
21
  def self.get_genre_pages
22
22
  agent = Mechanize.new
23
- NYTBestsellers::Genre.all.collect do |genre|
23
+ Genre.all.collect do |genre|
24
24
  page = agent.get("#{genre.url}")
25
25
  end
26
26
  end
@@ -30,7 +30,7 @@ class NYTBestsellers::Scraper
30
30
  books = page.css("div.book-body")
31
31
 
32
32
  books.each do |book|
33
- NYTBestsellers::Book.new(
33
+ Book.new(
34
34
  page.css("h1").text.split(/\s-\s/)[0].strip, #genre
35
35
  book.css("h2.title").text.split.collect(&:capitalize).join(" "),
36
36
  book.css("p.author").text.split.delete_if{|x| x == "by"}.join(" "),
@@ -44,6 +44,5 @@ class NYTBestsellers::Scraper
44
44
 
45
45
  def self.get_date
46
46
  get_page.css("div.date-range").text.strip
47
- end
48
-
47
+ end
49
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nyt-bestsellers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amy Back