best_nba_players_18 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +2 -0
- data/best_nba_players_18.gemspec +44 -0
- data/bin/best_nba_players_18 +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/best_nba_players_18.rb +13 -0
- data/lib/best_nba_players_18/cli.rb +154 -0
- data/lib/best_nba_players_18/players.rb +70 -0
- data/lib/best_nba_players_18/scraper.rb +85 -0
- data/lib/best_nba_players_18/version.rb +3 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 325fb0867855cad738730d4bc918590f9603c04c
|
4
|
+
data.tar.gz: 84f284f716446b51f60f6ef7c1fa7b5254e47e65
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4556056e38039a5341a4a136ad2f9ab1fcdabe043f30d973bc6eb6d53506dcec83df28bdd8445423c21df7809336dd247babf02b8d6cedf657d545be86a03cfd
|
7
|
+
data.tar.gz: 9f292ffe7f86f595e5abc0d638ccf9f89b6cbb0060208e073c4f80e8658379b45158caed54bc07612f525ad45b5ea06fe446459b0756158f8ea0b3f45830708e
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at 'macdowell@noukod.com'. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
best_nba_players_18 (0.1.0)
|
5
|
+
colorize (~> 0.8.0)
|
6
|
+
nokogiri (~> 1.8, >= 1.8.4)
|
7
|
+
terminal-table (~> 1.8, >= 1.7.9)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
coderay (1.1.2)
|
13
|
+
colorize (0.8.1)
|
14
|
+
method_source (0.9.0)
|
15
|
+
mini_portile2 (2.3.0)
|
16
|
+
nokogiri (1.8.5-x64-mingw32)
|
17
|
+
mini_portile2 (~> 2.3.0)
|
18
|
+
pry (0.11.3)
|
19
|
+
coderay (~> 1.1.0)
|
20
|
+
method_source (~> 0.9.0)
|
21
|
+
rake (10.5.0)
|
22
|
+
terminal-table (1.8.0)
|
23
|
+
unicode-display_width (~> 1.1, >= 1.1.1)
|
24
|
+
unicode-display_width (1.4.0)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
x64-mingw32
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
best_nba_players_18!
|
32
|
+
bundler (~> 1.16)
|
33
|
+
pry (~> 0.10)
|
34
|
+
rake (~> 10.0)
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
1.16.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 'Mac Dowell Prosper'
|
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/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Best NBA Players S(17-18)
|
2
|
+
|
3
|
+
This Ruby gem provides a command-line interface to display the Top 100 Players of the 2017-18 NBA Season based on the Washington Post website.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'best_nba_players_18'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install best_nba_players_18
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Type the below and follow the on screen prompts.
|
24
|
+
|
25
|
+
$ best_nba_players_18
|
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/dowpm/best_nba_players_18. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the BestNbaPlayersS18 project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dowpm/best_nba_players_18/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "best_nba_players_18/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "best_nba_players_18"
|
8
|
+
spec.version = BestNbaPlayersS18::VERSION
|
9
|
+
spec.authors = ["'Mac Dowell Prosper'"]
|
10
|
+
spec.email = ["'macdowell@noukod.com'"]
|
11
|
+
|
12
|
+
spec.summary = "This gem is for showing the top 100 nba players (season 17-18)"
|
13
|
+
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
14
|
+
spec.homepage = "https://github.com/dowpm/best_nba_players_18"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# spec.platform = Gem::Platform::RUBY
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
20
|
+
# if spec.respond_to?(:metadata)
|
21
|
+
# # spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
22
|
+
# else
|
23
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
24
|
+
# "public gem pushes."
|
25
|
+
# end
|
26
|
+
|
27
|
+
# Specify which files should be added to the gem when it is released.
|
28
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
29
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
30
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
31
|
+
end
|
32
|
+
# spec.bindir = "exe"
|
33
|
+
# spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
34
|
+
spec.executables << "best_nba_players_18"
|
35
|
+
spec.require_paths = ["lib"]
|
36
|
+
|
37
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
38
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
39
|
+
|
40
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
41
|
+
spec.add_dependency "nokogiri", '~> 1.8', '>= 1.8.4'
|
42
|
+
spec.add_dependency "terminal-table", '~> 1.8', '>= 1.7.9'
|
43
|
+
spec.add_dependency "colorize", "~> 0.8.0"
|
44
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "best_nba_players_18"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "best_nba_players_18/version"
|
2
|
+
|
3
|
+
require 'pry'
|
4
|
+
require 'nokogiri'
|
5
|
+
require 'open-uri'
|
6
|
+
require 'terminal-table'
|
7
|
+
require 'colorize'
|
8
|
+
|
9
|
+
|
10
|
+
require 'best_nba_players_18/cli'
|
11
|
+
require 'best_nba_players_18/players'
|
12
|
+
require 'best_nba_players_18/scraper'
|
13
|
+
|
@@ -0,0 +1,154 @@
|
|
1
|
+
module BestNbaPlayersS18
|
2
|
+
class CLI
|
3
|
+
URL = "https://www.washingtonpost.com/graphics/2017/sports/nba-top-100-players-2017/?noredirect=on&utm_term=.adcc13ae7e38"
|
4
|
+
COLORIER = ->(player){
|
5
|
+
color = ""
|
6
|
+
color = :green if player.trend == "up"
|
7
|
+
color = :red if player.trend == "down"
|
8
|
+
color
|
9
|
+
}
|
10
|
+
|
11
|
+
def self.run
|
12
|
+
collections = BestNbaPlayersS18::Scraper.scrape_page(URL)
|
13
|
+
BestNbaPlayersS18::Players.create_players_from_collection collections
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.start
|
17
|
+
run
|
18
|
+
system "cls" or system "clear"
|
19
|
+
puts "Welcome to best_nba_players_18 gem","--**player's trend ("+"upswing".colorize(:green)+", constant, "+"decline".colorize(:red)+ ") .**--\n"
|
20
|
+
input = ""
|
21
|
+
until input == "n" or input == "no"
|
22
|
+
opt = -1
|
23
|
+
until opt > 0 and opt <= 10
|
24
|
+
puts "Invalid input!!! \n" if opt == 0 or opt >= 10
|
25
|
+
rows = [
|
26
|
+
["1. List all players by ranking","2. List all players by Age"],
|
27
|
+
["3. List all players by points","4. List all players by rebounds"],
|
28
|
+
["5. List all players by assists","6. List all players by 3pt"],
|
29
|
+
["7. List all players by blocks","8. List all players by free throw"],
|
30
|
+
["9. Group by trend","10. Exit"],
|
31
|
+
]
|
32
|
+
puts Terminal::Table.new :title => "Menu", :rows => rows, :style => {:all_separators => true}
|
33
|
+
print "=> "
|
34
|
+
opt = gets.strip.to_i
|
35
|
+
|
36
|
+
system "cls" or system "clear"
|
37
|
+
end
|
38
|
+
|
39
|
+
break if opt == 10
|
40
|
+
|
41
|
+
if opt != 9
|
42
|
+
#sort the @@all by_input
|
43
|
+
#return an array for stats
|
44
|
+
order = BestNbaPlayersS18::Players.sort opt
|
45
|
+
|
46
|
+
until input == "n" or input == "no"
|
47
|
+
puts "\n What number of players do you want to see? 1-20, 21-40, 41-60, 61-80 or 81-100? "
|
48
|
+
print "=> "
|
49
|
+
n_palyer = gets.strip.to_i
|
50
|
+
n_palyer = 1 if n_palyer == 0
|
51
|
+
|
52
|
+
#print_players index
|
53
|
+
print_players n_palyer, order if order.class == String
|
54
|
+
print_players n_palyer, order[0], order[1] if order.class == Array
|
55
|
+
|
56
|
+
puts "What player do you want to see more information on?"
|
57
|
+
print "=> "
|
58
|
+
input = gets.strip.to_i
|
59
|
+
|
60
|
+
#print_player index
|
61
|
+
player = BestNbaPlayersS18::Players.find input
|
62
|
+
print_player player
|
63
|
+
|
64
|
+
puts "Do you want to see information about another player? (y/n)"
|
65
|
+
print "=> "
|
66
|
+
input = gets.strip.downcase
|
67
|
+
end
|
68
|
+
else
|
69
|
+
until input == "n" or input == "no"
|
70
|
+
puts "\n What group of trends do you want to see?"," (1- constant, 2-"+" upswing".colorize(:green)+", 3-"+" decline".colorize(:red)+")"
|
71
|
+
print "=> "
|
72
|
+
n_trend = gets.strip.to_i
|
73
|
+
n_trend = 1 if n_trend == 0
|
74
|
+
|
75
|
+
choices = ["neutral", "up", "down"]
|
76
|
+
by_input = choices[n_trend-1]
|
77
|
+
|
78
|
+
#print_players group by_input
|
79
|
+
print_players_group by_input
|
80
|
+
|
81
|
+
puts "What player do you want to see more information on?"
|
82
|
+
print "=> "
|
83
|
+
input = gets.strip.to_i
|
84
|
+
|
85
|
+
#print_player index
|
86
|
+
player = BestNbaPlayersS18::Players.find_group input, by_input
|
87
|
+
print_player player
|
88
|
+
|
89
|
+
puts "Do you want to see information about another player? (y/n)"
|
90
|
+
print "=> "
|
91
|
+
input = gets.strip.downcase
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
puts "Do you want to list all players? (y/n)"
|
96
|
+
print "=> "
|
97
|
+
input = gets.strip.downcase
|
98
|
+
# system "cls" or system "clear"
|
99
|
+
end
|
100
|
+
|
101
|
+
puts "Goodbye !!"
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.print_players(from_number, order = "rank", stats = "")
|
106
|
+
|
107
|
+
if stats == ""
|
108
|
+
rows = BestNbaPlayersS18::Players.all[from_number-1, 20].each.with_index(from_number).map do |player, index|
|
109
|
+
[index, player.name.colorize(COLORIER.(player)), "#{order}:#{player.send(order)}"]
|
110
|
+
end
|
111
|
+
else
|
112
|
+
rows = BestNbaPlayersS18::Players.all[from_number-1, 20].each.with_index(from_number).map do |player, index|
|
113
|
+
[index, player.name.colorize(COLORIER.(player)), "#{stats} : #{player.send(order)[stats.to_sym]}"]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
puts Terminal::Table.new :title => "Players #{from_number} - #{from_number+19}", :rows => rows, :style => {:all_separators => true}
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.print_player player
|
121
|
+
table = Terminal::Table.new :title => "#{player.name}", :rows => [
|
122
|
+
["Age", player.statistics[:AGE].colorize(COLORIER.(player))],
|
123
|
+
["Position", player.position.colorize(COLORIER.(player))],
|
124
|
+
["Team", player.team.colorize(COLORIER.(player))],
|
125
|
+
["Rank", player.rank.to_s.colorize(COLORIER.(player))],
|
126
|
+
["PPG", player.statistics[:PPG].to_s.colorize(COLORIER.(player))],
|
127
|
+
["RPG", player.statistics[:RPG].to_s.colorize(COLORIER.(player))],
|
128
|
+
["APG", player.statistics[:APG].to_s.colorize(COLORIER.(player))],
|
129
|
+
["BLK", player.statistics[:BLK].to_s.colorize(COLORIER.(player))],
|
130
|
+
["FT", player.statistics[:FT].to_s.colorize(COLORIER.(player))],
|
131
|
+
["Steal", player.statistics[:STL].to_s.colorize(COLORIER.(player))],
|
132
|
+
["FG", player.statistics[:FG].to_s.colorize(COLORIER.(player))],
|
133
|
+
["3PT", player.statistics[:THREEPT].to_s.colorize(COLORIER.(player))]
|
134
|
+
]
|
135
|
+
puts table
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.print_players_group by_input
|
139
|
+
arr, rows = [], []
|
140
|
+
BestNbaPlayersS18::Players.group(by_input).each.with_index(1) do |player, i|
|
141
|
+
|
142
|
+
arr.push i, player.name.colorize(COLORIER.(player)), " "
|
143
|
+
if arr.size == 6
|
144
|
+
rows << arr
|
145
|
+
arr = []
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
title = {up: "UPSWING".colorize(:green), down: "DECLINE".colorize(:red), neutral: "CONSTANT"}
|
150
|
+
puts Terminal::Table.new :title => title[by_input.to_sym], :rows => rows, :style =>{:all_separators => true}
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module BestNbaPlayersS18
|
2
|
+
class BestNbaPlayersS18::Players
|
3
|
+
attr_accessor :trend, :name, :team, :position, :statistics, :rank, :info
|
4
|
+
@@all = []
|
5
|
+
|
6
|
+
def self.all
|
7
|
+
@@all
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize infos_hash
|
11
|
+
infos_hash.each do |info, value|
|
12
|
+
self.send("#{info}=",value)
|
13
|
+
end
|
14
|
+
@@all << self
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.create_players_from_collection collection
|
18
|
+
collection.each do |players|
|
19
|
+
players.each {|infos_hash| new(infos_hash) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.find input
|
24
|
+
all[input-1]
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.sort(input = 1)
|
28
|
+
# choice = ["rank","name","position","team","AGE","PPG","RPG","APG","STL","FG","FT","THREEPT","BLK"]
|
29
|
+
choices = ["rank","AGE","PPG","RPG","APG","THREEPT","BLK","FT"]
|
30
|
+
by_input = choices[input-1]
|
31
|
+
if input > 1
|
32
|
+
return sort_asc by_input, true if by_input == "AGE"
|
33
|
+
return sort_desc by_input
|
34
|
+
else
|
35
|
+
return sort_asc by_input
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.sort_asc by_input, stats = false
|
40
|
+
if !stats
|
41
|
+
all.sort! do |player1, player2|
|
42
|
+
player1.send(by_input) <=> player2.send(by_input)
|
43
|
+
end
|
44
|
+
return by_input
|
45
|
+
else
|
46
|
+
all.sort! do |player1, player2|
|
47
|
+
player1.send("statistics")[by_input.to_sym] <=> player2.send("statistics")[by_input.to_sym]
|
48
|
+
end
|
49
|
+
return ["statistics",by_input]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
def self.sort_desc by_input, stats = false
|
53
|
+
all.sort! do |player1, player2|
|
54
|
+
player2.send("statistics")[by_input.to_sym] <=> player1.send("statistics")[by_input.to_sym]
|
55
|
+
end
|
56
|
+
return ["statistics",by_input]
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.group by_input
|
60
|
+
all.select do |player|
|
61
|
+
player.trend == by_input
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.find_group index, by_input
|
66
|
+
group(by_input)[index-1]
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module BestNbaPlayersS18
|
2
|
+
class BestNbaPlayersS18::Scraper
|
3
|
+
|
4
|
+
def self.scrape_page url
|
5
|
+
nokogiri_url = Nokogiri::HTML(open(url))
|
6
|
+
players_neutral_nokogiri = nokogiri_url.search(".player-container.trend-neutral div.player-info-inner")
|
7
|
+
players_up_nokogiri = nokogiri_url.search(".player-container.trend-up div.player-info-inner")
|
8
|
+
players_down_nokogiri = nokogiri_url.search(".player-container.trend-down div.player-info-inner")
|
9
|
+
|
10
|
+
players_neutral = players_neutral_nokogiri.map do |p|
|
11
|
+
stats = p.css("ul.player-info-barns li").text.gsub("\s","").split("\n\n")
|
12
|
+
{
|
13
|
+
trend: "neutral",
|
14
|
+
rank: p.css(".player-info-name").children[1].text.strip.to_i,
|
15
|
+
name: p.css(".player-info-name").children[2].text.strip,
|
16
|
+
position: p.css("p")[0].text.split(", ")[0],
|
17
|
+
team: p.css("p")[0].text.split(", ")[1],
|
18
|
+
info: p.css("p")[1].text,
|
19
|
+
statistics: {
|
20
|
+
PPG: stats[0].split("\n")[-1].to_f,
|
21
|
+
RPG: stats[1].split("\n")[-1].to_f,
|
22
|
+
APG: stats[3].split("\n")[-1].to_f,
|
23
|
+
AGE: stats[5].split("\n")[-1],
|
24
|
+
STL: stats[6].split("\n")[-1].to_f,
|
25
|
+
FG: stats[7].split("\n")[-1].to_f,
|
26
|
+
FT: stats[8].split("\n")[-1].to_f,
|
27
|
+
THREEPT: stats[9].split("\n")[-1].to_f,
|
28
|
+
BLK: stats[10].split("\n")[-1].to_f
|
29
|
+
}
|
30
|
+
|
31
|
+
}
|
32
|
+
end
|
33
|
+
players_up = players_up_nokogiri.map do |p|
|
34
|
+
stats = p.css("ul.player-info-barns li").text.gsub("\s","").split("\n\n")
|
35
|
+
{
|
36
|
+
trend: "up",
|
37
|
+
rank: p.css(".player-info-name").children[1].text.strip.to_i,
|
38
|
+
name: p.css(".player-info-name").children[2].text.strip,
|
39
|
+
position: p.css("p")[0].text.split(", ")[0],
|
40
|
+
team: p.css("p")[0].text.split(", ")[1],
|
41
|
+
info: p.css("p")[1].text,
|
42
|
+
statistics: {
|
43
|
+
PPG: stats[0].split("\n")[-1].to_f,
|
44
|
+
RPG: stats[1].split("\n")[-1].to_f,
|
45
|
+
APG: stats[3].split("\n")[-1].to_f,
|
46
|
+
AGE: stats[5].split("\n")[-1],
|
47
|
+
STL: stats[6].split("\n")[-1].to_f,
|
48
|
+
FG: stats[7].split("\n")[-1].to_f,
|
49
|
+
FT: stats[8].split("\n")[-1].to_f,
|
50
|
+
THREEPT: stats[9].split("\n")[-1].to_f,
|
51
|
+
BLK: stats[10].split("\n")[-1].to_f
|
52
|
+
}
|
53
|
+
|
54
|
+
}
|
55
|
+
end
|
56
|
+
players_down = players_down_nokogiri.map do |p|
|
57
|
+
stats = p.css("ul.player-info-barns li").text.gsub("\s","").split("\n\n")
|
58
|
+
{
|
59
|
+
trend: "down",
|
60
|
+
rank: p.css(".player-info-name").children[1].text.strip.to_i,
|
61
|
+
name: p.css(".player-info-name").children[2].text.strip,
|
62
|
+
position: p.css("p")[0].text.split(", ")[0],
|
63
|
+
team: p.css("p")[0].text.split(", ")[1],
|
64
|
+
info: p.css("p")[1].text,
|
65
|
+
statistics: {
|
66
|
+
PPG: stats[0].split("\n")[-1].to_f,
|
67
|
+
RPG: stats[1].split("\n")[-1].to_f,
|
68
|
+
APG: stats[3].split("\n")[-1].to_f,
|
69
|
+
AGE: stats[5].split("\n")[-1],
|
70
|
+
STL: stats[6].split("\n")[-1].to_f,
|
71
|
+
FG: stats[7].split("\n")[-1].to_f,
|
72
|
+
FT: stats[8].split("\n")[-1].to_f,
|
73
|
+
THREEPT: stats[9].split("\n")[-1].to_f,
|
74
|
+
BLK: stats[10].split("\n")[-1].to_f
|
75
|
+
}
|
76
|
+
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
# binding.pry
|
81
|
+
return players_neutral, players_up, players_down
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: best_nba_players_18
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "'Mac Dowell Prosper'"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-06 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.8'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.8.4
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '1.8'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.8.4
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: terminal-table
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '1.8'
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 1.7.9
|
85
|
+
type: :runtime
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '1.8'
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.7.9
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: colorize
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.8.0
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 0.8.0
|
109
|
+
description:
|
110
|
+
email:
|
111
|
+
- "'macdowell@noukod.com'"
|
112
|
+
executables:
|
113
|
+
- best_nba_players_18
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- ".gitignore"
|
118
|
+
- CODE_OF_CONDUCT.md
|
119
|
+
- Gemfile
|
120
|
+
- Gemfile.lock
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- best_nba_players_18.gemspec
|
125
|
+
- bin/best_nba_players_18
|
126
|
+
- bin/console
|
127
|
+
- bin/setup
|
128
|
+
- lib/best_nba_players_18.rb
|
129
|
+
- lib/best_nba_players_18/cli.rb
|
130
|
+
- lib/best_nba_players_18/players.rb
|
131
|
+
- lib/best_nba_players_18/scraper.rb
|
132
|
+
- lib/best_nba_players_18/version.rb
|
133
|
+
homepage: https://github.com/dowpm/best_nba_players_18
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.6.14.1
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: This gem is for showing the top 100 nba players (season 17-18)
|
157
|
+
test_files: []
|