bookworm_best_sellers 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1c296124b0ea6f47b5a83215d15edd34763f0d5d
4
+ data.tar.gz: 2896894586b75f2ca674559772efa34d91d920da
5
+ SHA512:
6
+ metadata.gz: 1944d209958b0609b33e70a9992dc8b4f9b860378c3031c0d763b44d5851ffd9b7bed0b8d57505174db6be1b0efa06527957ec420eb113972d6012c1bb98c19b
7
+ data.tar.gz: 52f66cb022dd46f31a5272b2ebbbb91da22ecf882158057f2afc6cd157e5df012df69bdf78ed563f545dc9026d3eadfcc81d9bccd260389e49dd02998c870ad0
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bookworm_best_sellers (1.0.0)
5
+ nokogiri
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.1)
11
+ diff-lcs (1.2.5)
12
+ method_source (0.8.2)
13
+ mini_portile2 (2.1.0)
14
+ nokogiri (1.6.8)
15
+ mini_portile2 (~> 2.1.0)
16
+ pkg-config (~> 1.1.7)
17
+ pkg-config (1.1.7)
18
+ pry (0.10.3)
19
+ coderay (~> 1.1.0)
20
+ method_source (~> 0.8.1)
21
+ slop (~> 3.4)
22
+ rake (10.4.2)
23
+ rspec (3.4.0)
24
+ rspec-core (~> 3.4.0)
25
+ rspec-expectations (~> 3.4.0)
26
+ rspec-mocks (~> 3.4.0)
27
+ rspec-core (3.4.4)
28
+ rspec-support (~> 3.4.0)
29
+ rspec-expectations (3.4.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.4.0)
32
+ rspec-mocks (3.4.1)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.4.0)
35
+ rspec-support (3.4.1)
36
+ slop (3.6.0)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ bookworm_best_sellers!
43
+ bundler (~> 1.10)
44
+ pry
45
+ rake (~> 10.0)
46
+ rspec
47
+
48
+ BUNDLED WITH
49
+ 1.12.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 aviflombaum
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Notes.md ADDED
@@ -0,0 +1,32 @@
1
+ How to Build a CLI Gem
2
+
3
+ 1. Plan your gem, imagine your interface
4
+ 2. Start with the project structure - google
5
+ 3. Start with the entry point - the file run
6
+ 4. force that to build the CLI interface
7
+ 5. stub out the interface
8
+ 6. start making things real
9
+ 7. discover objects.
10
+ 8. program
11
+
12
+
13
+
14
+ - A command line interface for daily deals, starting with woot and meh.
15
+
16
+ user types daily-deal
17
+
18
+ Show a list of products
19
+
20
+ 1. PCH Digital Pulse Massager - $27 - Still available!
21
+ 2. Lenovo ThinkPad 11E 11.6 - $199.99 - Still available!
22
+
23
+ Which product do you want to learn more about?
24
+
25
+ 1
26
+
27
+ What is a deal?
28
+
29
+ A deal has a name
30
+ A deal has a price
31
+ A deal has a URL
32
+ a deal has an avaiablity.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Bookworm Best Sellers
2
+
3
+ The Bookworm gem provides the current week's bestselling books in the USA according to the New York Times. Best Selling Book list is live updated when the gem is executed via the CLI in bin/bookworm
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bookworm_best_sellers'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install bookworm_best_sellers
20
+
21
+ ## Usage
22
+
23
+ Current usage is via CLI, which will allow the output of the top 10 best selling books for the current week along with description, author, and ranking.
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wsaxe/bookworm-best-sellers. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/bookworm ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bookworm_best_sellers"
5
+
6
+ BookwormBestSellers::CLI.new.call
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bookworm_best_sellers"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bookworm_best_sellers/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bookworm_best_sellers"
8
+ spec.version = BookwormBestSellers::VERSION
9
+ spec.authors = ["William Saxe"]
10
+ spec.email = ["geosaxe@gmail.com"]
11
+
12
+ spec.summary = %q{The Bookworm gem provides the current week's bestselling books in the USA.}
13
+ spec.description = %q{The Bookworm gem provides the current week's bestselling books in the USA according to the New York Times. Best Selling Book list is live updated when the gem is executed.}
14
+ spec.homepage = "https://github.com/wsaxe/bookworm-best-sellers"
15
+ spec.license = "MIT"
16
+
17
+
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "pry"
28
+
29
+ spec.add_dependency "nokogiri"
30
+ end
@@ -0,0 +1,59 @@
1
+ class BookwormBestSellers::Book
2
+ attr_accessor :title, :author, :description, :url
3
+ @@current_book_list = []
4
+ @@current_descriptions = []
5
+ @@doc = Nokogiri::HTML(open("http://www.barnesandnoble.com/b/the-new-york-times-bestsellers-hardcover-nonfiction/_/N-1p5q"))
6
+
7
+ def self.this_week
8
+ if @@current_book_list == []
9
+ @@current_book_list = self.scrape_books
10
+ else
11
+ @@current_book_list
12
+ end
13
+ end
14
+
15
+ def self.scrape_books
16
+ books = []
17
+ self.scrape_titles.each do |ind_title|
18
+ if books.length < 10
19
+ book = self.new
20
+ book.title = ind_title
21
+ books << book
22
+ end
23
+ end
24
+ books.each.with_index(0) do |ind_book, i|
25
+ ind_book.author = self.scrape_authors[i]
26
+ end
27
+ books.each.with_index(0) do |ind_book, i|
28
+ ind_book.url = ["http://www.barnesandnoble.com",self.scrape_urls[i]].join()
29
+ end
30
+ books.each.with_index(0) do |ind_book, i|
31
+ ind_book.description = self.scrape_descriptions[i]
32
+ end
33
+ books
34
+ end
35
+
36
+ def self.scrape_titles
37
+ @@doc.search("p.product-info-title").text.split("\n").reject { |item| item.nil? || item == "" }.map { |ind_title| ind_title[0...-13] }
38
+ end
39
+
40
+ def self.scrape_authors
41
+ @@doc.search("span.contributor").to_s.split("/a").map! { |author| author[-25..-1] }.reject { |author| author.nil? || author == "" }.map! { |author| author.split(">")[1] }.map! { |ind_author| ind_author[0...-1] }
42
+ end
43
+
44
+ def self.scrape_urls
45
+ [*0..9].map! { |index| @@doc.css("p.product-info-title a")[index]['href'].split(";")[0] }
46
+ end
47
+
48
+ def self.scrape_descriptions
49
+ if @@current_descriptions == []
50
+ @@current_descriptions = [*0..9].map! do |i|
51
+ url = ["http://www.barnesandnoble.com",self.scrape_urls[i]].join()
52
+ Nokogiri::HTML(open(url)).css('div#productInfoOverview p').text.split("\n").reject { |item| item.nil? || item == "" }[0]
53
+ end
54
+ else
55
+ @@current_descriptions
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,47 @@
1
+ class BookwormBestSellers::CLI
2
+
3
+ def call
4
+ puts "\nLOADING BEST SELLERS..."
5
+ list_books
6
+ prompt
7
+ end
8
+
9
+ def list_books
10
+ @books = BookwormBestSellers::Book.this_week
11
+ puts "\nBest Sellers - Week of #{current_week}\n\n"
12
+ @books.each.with_index(1) do |book, i|
13
+ puts "#{i}. #{book.title} - #{book.author}"
14
+ end
15
+ end
16
+
17
+ def current_week
18
+ time = Time.new
19
+ if time.wday == 0
20
+ time.strftime("%B %d, %Y")
21
+ else
22
+ sunday = time - (time.wday * 86400)
23
+ sunday.strftime("%B %d, %Y")
24
+ end
25
+ end
26
+
27
+ def prompt
28
+ puts "\nType a number to learn more about a book, LIST to see the list again, or type EXIT."
29
+ input = gets.strip.downcase
30
+ if input.to_i > 0 && input.to_i < 11
31
+ puts "\n#{@books[input.to_i-1].description}"
32
+ prompt
33
+ elsif input == "exit"
34
+ exit_message
35
+ elsif input == "list"
36
+ list_books
37
+ prompt
38
+ else
39
+ puts "\nINVALID CHOICE"
40
+ prompt
41
+ end
42
+ end
43
+
44
+ def exit_message
45
+ puts "\nThanks for using Bookworm! Have a great day!\n\n"
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module BookwormBestSellers
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'pry'
4
+
5
+ require_relative "./bookworm_best_sellers/version"
6
+ require_relative './bookworm_best_sellers/book'
7
+ require_relative './bookworm_best_sellers/cli'
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bookworm_best_sellers
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - William Saxe
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: The Bookworm gem provides the current week's bestselling books in the
84
+ USA according to the New York Times. Best Selling Book list is live updated when
85
+ the gem is executed.
86
+ email:
87
+ - geosaxe@gmail.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".rspec"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - Notes.md
98
+ - README.md
99
+ - Rakefile
100
+ - bin/bookworm
101
+ - bin/console
102
+ - bin/setup
103
+ - bookworm_best_sellers.gemspec
104
+ - lib/bookworm_best_sellers.rb
105
+ - lib/bookworm_best_sellers/book.rb
106
+ - lib/bookworm_best_sellers/cli.rb
107
+ - lib/bookworm_best_sellers/version.rb
108
+ homepage: https://github.com/wsaxe/bookworm-best-sellers
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.4.5.1
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: The Bookworm gem provides the current week's bestselling books in the USA.
132
+ test_files: []