bestsellers 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 548426c2c817ce9caeb473410570948f3b94d733928e39b2f0abb4f9b816e010
4
+ data.tar.gz: cd91986c62a4d47887ece18b315a26a6b5e68fb7ba0ab3bf03b489f3247903c8
5
+ SHA512:
6
+ metadata.gz: 30a1efaf3a6c2452385cbf99f282885575f6ef598e006c79662a5b76a39e651ddf24fe0b4d456594d5cabc6d5d59162b96e0371cfd4374d3970164a31a9c4288
7
+ data.tar.gz: 808385e07a7cef1e28ddb36149690de81f91d580578b23f92b333940470ef3df1fedc1dc59d9e6cbac0cf3f5168483712a9d7b6d3247995b4b4ca33fcc6bfecf
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bestsellers.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bestsellers (0.1.0)
5
+ nokogiri
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ method_source (0.9.2)
12
+ mini_portile2 (2.4.0)
13
+ nokogiri (1.10.5-x64-mingw32)
14
+ mini_portile2 (~> 2.4.0)
15
+ pry (0.12.2)
16
+ coderay (~> 1.1.0)
17
+ method_source (~> 0.9.0)
18
+ rake (10.5.0)
19
+
20
+ PLATFORMS
21
+ x64-mingw32
22
+
23
+ DEPENDENCIES
24
+ bestsellers!
25
+ bundler (~> 2.0)
26
+ pry
27
+ rake (~> 10.0)
28
+
29
+ BUNDLED WITH
30
+ 2.0.2
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # BESTSELLERS
2
+
3
+ Welcome to the Bestsellers gem. This gem allows you to view the current best selling books. You can also select from the best selling book list the book you are interested in to get more information about that specific book.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bestsellers'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install bestsellers
20
+
21
+ ## Usage
22
+
23
+ Once you have completed installing the gem, simply run the following code to get the gem started:
24
+
25
+ $ bin/best-sellers
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/h-miiaah/bestsellers.
36
+
37
+ ## License
38
+
39
+ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "bestsellers/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bestsellers"
7
+ spec.version = Bestsellers::VERSION
8
+ spec.authors = "Haim"
9
+ spec.email = "email@email.email" # this email is just to fill in the spec.email section, it is not a real eamil.
10
+
11
+ spec.summary = %q{"Lists the current best selling books."}
12
+ spec.description = %q{"Lists the current best selling books."}
13
+ # spec.homepage = "Put your gem's website or public repo URL here."
14
+ spec.license = "MIT"
15
+
16
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
17
+
18
+ # spec.metadata["homepage_uri"] = spec.homepage
19
+ # spec.metadata["source_code_uri"] = "Put your gem's public repo URL here."
20
+ # spec.metadata["changelog_uri"] = "Put your gem's CHANGELOG.md URL here."
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 2.0"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "pry"
34
+ spec.add_dependency "nokogiri"
35
+ end
data/bin/best-sellers ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bestsellers"
5
+
6
+ Bestsellers::CLI.new.call
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bestsellers"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,16 @@
1
+ class Bestsellers::Books
2
+ attr_accessor :title, :author, :price, :url
3
+ @@books = []
4
+
5
+ def initialize(title, author,price, url)
6
+ @title = title
7
+ @author = author
8
+ @price = price
9
+ @url = url
10
+ @@books << self
11
+ end
12
+
13
+ def self.all
14
+ @@books
15
+ end
16
+ end
@@ -0,0 +1,63 @@
1
+ class Bestsellers::CLI
2
+
3
+ def call
4
+ Bestsellers::Scraper.create_bestsellers
5
+ welcome
6
+ list_books
7
+ puts " "
8
+ menu_selection
9
+ byebye
10
+ end
11
+
12
+ def welcome
13
+ puts <<-GREETING
14
+
15
+ ██████╗ ███████╗███████╗████████╗███████╗███████╗██╗ ██╗ ███████╗██████╗ ███████╗
16
+ ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔════╝██╔════╝██║ ██║ ██╔════╝██╔══██╗██╔════╝
17
+ ██████╔╝█████╗ ███████╗ ██║ ███████╗█████╗ ██║ ██║ █████╗ ██████╔╝███████╗
18
+ ██╔══██╗██╔══╝ ╚════██║ ██║ ╚════██║██╔══╝ ██║ ██║ ██╔══╝ ██╔══██╗╚════██║
19
+ ██████╔╝███████╗███████║ ██║ ███████║███████╗███████╗███████╗███████╗██║ ██║███████║
20
+ ╚═════╝ ╚══════╝╚══════╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚══════╝╚══════╝╚═╝ ╚═╝╚══════╝
21
+ The Best Selling Books You Must Read!
22
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
23
+
24
+ GREETING
25
+ end
26
+
27
+ def list_books
28
+ @bestseller_books = Bestsellers::Books.all
29
+ @bestseller_books.each.with_index(1) do |book, index|
30
+ puts "#{index}. #{book.title}"
31
+ end
32
+ end
33
+
34
+ def menu_selection
35
+ input = ""
36
+ while input != "exit"
37
+ puts "Enter the number of the book you want more information on, type 'list' to view the bestsellers list, or type 'exit' to exit."
38
+ puts " "
39
+ input = gets.strip.downcase
40
+
41
+ if input == "list"
42
+ list_books
43
+ puts " "
44
+ elsif input.to_i > 20
45
+ puts "Please enter a valid number from the bestsellers list."
46
+ elsif input.to_i > 0
47
+ user_selection = @bestseller_books[input.to_i - 1]
48
+ puts "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
49
+ puts "Title: #{user_selection.title}"
50
+ puts "Author: #{user_selection.author}"
51
+ puts "Price: #{user_selection.price}"
52
+ puts "URL: #{user_selection.url}"
53
+ puts "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
54
+ end
55
+ end
56
+ end
57
+
58
+ def byebye
59
+ puts " "
60
+ puts "Thank you for visiting Bestsellers! Enjoy reading your new book!"
61
+ end
62
+
63
+ end
@@ -0,0 +1,23 @@
1
+ require 'pry'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ class Bestsellers::Scraper
6
+
7
+ def self.todays_bestsellers
8
+ self.select_bestsellers
9
+ end
10
+
11
+ def self.create_bestsellers
12
+ doc = Nokogiri::HTML(open("https://www.barnesandnoble.com/b/books/_/N-1fZ29Z8q8"))
13
+ books = doc.css("ol.product-shelf-list.product-list-view li")
14
+ books.each do |book|
15
+ title = book.css("h3.product-info-title a").text.strip
16
+ author = book.css("div.product-shelf-author a").text.strip
17
+ price = book.css("a.current").text.strip
18
+ url = "https://www.barnesandnoble.com" + book.css("h3.product-info-title a").attr("href")
19
+ Bestsellers::Books.new(title, author, price, url)
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,3 @@
1
+ module Bestsellers
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'pry'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+
6
+ require_relative "./bestsellers/version"
7
+ require_relative "./bestsellers/cli"
8
+ require_relative "./bestsellers/books"
9
+ require_relative "./bestsellers/scraper"
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bestsellers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Haim
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-11-26 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
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: pry
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: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: '"Lists the current best selling books."'
70
+ email: email@email.email
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - Gemfile
76
+ - Gemfile.lock
77
+ - README.md
78
+ - Rakefile
79
+ - bestsellers.gemspec
80
+ - bin/best-sellers
81
+ - bin/console
82
+ - bin/setup
83
+ - lib/bestsellers.rb
84
+ - lib/bestsellers/books.rb
85
+ - lib/bestsellers/cli.rb
86
+ - lib/bestsellers/scraper.rb
87
+ - lib/bestsellers/version.rb
88
+ homepage:
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.0.3
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: '"Lists the current best selling books."'
111
+ test_files: []