knicks_history 0.1.1

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: 18ac1a4fc9eedb7877783078c254bc81a85587f04538856aa160947863e6e4e3
4
+ data.tar.gz: 92f4f88d44165b878e642517dd2f8085d52fbb46aaeb5478bb44870fe7a43307
5
+ SHA512:
6
+ metadata.gz: 9848190036cd070dd3613e3b02510bfb07f84d4d074f8d0f6c1f6360139b32314aa319461f398bb911312e11c04aeb1895a13c35cebb25938ce6bf040fe94bc2
7
+ data.tar.gz: 6413077db029bcdb7c8e9b231fbecc9b6f95ea973848b0a0823c10243f24ebd6771886c542fb0ef111456f60968b63116976c103e907391d8f2f375e4c2bff47
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.15.4
@@ -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 'stephanos@goldmail.etsu.edu'. 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
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in knicks_history.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 'Dembe Stephanos'
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
+ # KnicksHistory
2
+
3
+ This is a CLI application that utilizes Nokogiri to scrape information about the New York Knicks from BasketballReference.com
4
+ and provide this information, organized by season, in a clean command line output. This app uses a menu for navigation, and
5
+ implements and object oriented structure to create and display the individual Knicks seasons as scraped from the website.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'knicks_history'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install knicks_history
22
+
23
+ ## Usage
24
+
25
+ Just follow the menu prompts, and select the year for which you would like to see statistics for.
26
+
27
+ ## Development
28
+
29
+ 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.
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/'dkStephanos'/knicks_history. 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](http://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the KnicksHistory project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/'dkStephanos'/knicks_history/blob/master/CODE_OF_CONDUCT.md).
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/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "knicks_history"
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__)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/knicks_history"
4
+
5
+ KnicksHistory::CLI.new.call
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,7 @@
1
+ require 'pry'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ require_relative '../lib/knicks_history/scraper'
6
+ require_relative '../lib/knicks_history/season'
7
+ require_relative '../lib/knicks_history/cli'
Binary file
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "knicks_history/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "knicks_history"
8
+ spec.version = KnicksHistory::VERSION
9
+ spec.authors = ["'Dembe Stephanos'"]
10
+ spec.email = ["'stephanos@goldmail.etsu.edu'"]
11
+
12
+ spec.summary = %q{CLI App providing statistics for New York Knicks seasons.}
13
+ spec.homepage = "https://github.com/dkStephanos/KnicksHistoryCLI/tree/master/knicks_history"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ #if spec.respond_to?(:metadata)
19
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+ #else
21
+ # raise "RubyGems 2.0 or newer is required to protect against " \
22
+ # "public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.15"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ end
@@ -0,0 +1,5 @@
1
+ module KnicksHistory
2
+
3
+ end
4
+
5
+ require_relative "../config/enviornment"
@@ -0,0 +1,75 @@
1
+ class KnicksHistory::CLI
2
+
3
+ def call
4
+ scraper = KnicksHistory::Scraper.new
5
+ scraper.make_seasons
6
+ puts "New York Knicks - Statistics by Season"
7
+ start
8
+ end
9
+
10
+ def start
11
+ input = ""
12
+ while true
13
+ puts "\nWhich season would you like to see stats for? (Enter a year between 1946-2017) or type exit."
14
+ input = gets.strip
15
+ year = input.to_i
16
+ if year < 2018 && year > 1945
17
+ season = KnicksHistory::Season.find_season(year)
18
+ output_stats(season)
19
+ while true
20
+ puts "\nAdvanced Stats (enter the number of the statistic you want to see or type back)\n1. Offensive Rating\n2. Defensive Rating\n3. Best Player w/ Win Shares\n4. Offensive Pace\n5. Playoff Results"
21
+ secondary_input = gets.strip
22
+ case secondary_input
23
+ when "1"
24
+ output_off_rtng(season)
25
+ when "2"
26
+ output_def_rtng(season)
27
+ when "3"
28
+ output_best_player(season)
29
+ when "4"
30
+ output_pace(season)
31
+ when "5"
32
+ output_playoff_results(season)
33
+ when "back"
34
+ break
35
+ else
36
+ puts "\nSorry, must enter a number 1-3"
37
+ end
38
+ end
39
+ elsif input == "exit"
40
+ puts "\n\nThanks for using my gem! Go Knicks!"
41
+ break
42
+ else
43
+ puts "\nSorry, no season found for that selection. Try again."
44
+ end
45
+ end
46
+ end
47
+
48
+ def output_stats(season)
49
+ #prints stats for that year
50
+ puts "\n\nYear Wins Losses Win%"
51
+ #binding.pry
52
+ puts "#{season[1].year} #{season[1].wins} #{season[1].losses} #{season[1].win_percentage}"
53
+ end
54
+
55
+ def output_off_rtng(season)
56
+ puts "\n\nOff Rtng\n#{season[1].off_rating}"
57
+ end
58
+
59
+ def output_def_rtng(season)
60
+ puts "\n\nDef Rtng\n#{season[1].def_rating}"
61
+ end
62
+
63
+ def output_best_player(season)
64
+ puts "\n\nBest Player(WS)\n#{season[1].best_player_ws}"
65
+ end
66
+
67
+ def output_pace(season)
68
+ puts "\n\nPace\n#{season[1].pace}"
69
+ end
70
+
71
+ def output_playoff_results(season)
72
+ puts "\n\nPlayoff Results\n#{season[1].playoff_results}"
73
+ end
74
+
75
+ end
@@ -0,0 +1,35 @@
1
+ class KnicksHistory::Scraper
2
+
3
+ def get_page
4
+ Nokogiri::HTML(open("https://www.basketball-reference.com/teams/NYK/"))
5
+ end
6
+
7
+ def scrape_seasons_index
8
+ self.get_page.css("#NYK tbody tr")
9
+ end
10
+
11
+ def make_seasons
12
+ data_hash = {}
13
+ scrape_seasons_index.each do |season|
14
+ data_hash[:year] = season.css("th a").text.match(/\d{4}/).to_s
15
+ data_hash[:wins] = season.css("td[data-stat = wins]").text
16
+ data_hash[:losses] = season.css("td[data-stat = losses]").text
17
+ data_hash[:win_percentage] = season.css("td[data-stat = win_loss_pct]").text
18
+ if season.css("td[data-stat = off_rtg]").text == ""
19
+ data_hash[:off_rating] = "N/A"
20
+ data_hash[:def_rating] = "N/A"
21
+ else
22
+ data_hash[:off_rating] = season.css("td[data-stat = off_rtg]").text
23
+ data_hash[:def_rating] = season.css("td[data-stat = def_rtg]").text
24
+ end
25
+ data_hash[:best_player_ws] = season.css("td[data-stat = top_ws]").text
26
+ data_hash[:pace] = season.css("td[data-stat = pace]").text
27
+ if season.css("td[data-stat = rank_team_playoffs]").text == ""
28
+ data_hash[:playoff_results] = "Missed Playoffs"
29
+ else
30
+ data_hash[:playoff_results] = season.css("td[data-stat = rank_team_playoffs]").text
31
+ end
32
+ KnicksHistory::Season.new(data_hash)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,36 @@
1
+ class KnicksHistory::Season
2
+
3
+ attr_accessor :year, :wins, :losses, :win_percentage, :off_rating, :def_rating, :best_player_ws, :pace, :playoff_results
4
+
5
+ @@all = {}
6
+
7
+ def initialize(season_hash = nil)
8
+ if season_hash != nil
9
+ @year = season_hash[:year]
10
+ @wins = season_hash[:wins]
11
+ @losses = season_hash[:losses]
12
+ @win_percentage = season_hash[:win_percentage]
13
+ @off_rating = season_hash[:off_rating]
14
+ @def_rating = season_hash[:def_rating]
15
+ @best_player_ws = season_hash[:best_player_ws]
16
+ @pace = season_hash[:pace]
17
+ @playoff_results = season_hash[:playoff_results]
18
+ @@all[@year] = self
19
+ end
20
+ end
21
+
22
+ def self.all
23
+ @@all
24
+ end
25
+
26
+ def self.find_season(year)
27
+ @@all.detect do |season|
28
+ season[0] == year.to_s
29
+ end
30
+ end
31
+
32
+ def year
33
+ @year
34
+ end
35
+
36
+ end
@@ -0,0 +1,3 @@
1
+ module KnicksHistory
2
+ VERSION = "0.1.1"
3
+ end
data/spec.md ADDED
@@ -0,0 +1,7 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+ - [X] Have a CLI for interfacing with the application - Implemented in the CLI class.
5
+ - [X] Pull data from an external source - Implemented in Scraper class. Pulls data from basketball-reference.com/teams/NYK/
6
+ - [X] Implement both list and detail views - First menu selects a season and lists basic stats for that season. Afterwards a secondary
7
+ menu for advanced stats gives access to details of the season.
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knicks_history
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - "'Dembe Stephanos'"
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-14 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - "'stephanos@goldmail.etsu.edu'"
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/knicks-history
72
+ - bin/setup
73
+ - config/enviornment.rb
74
+ - knicks_history-0.1.0.gem
75
+ - knicks_history.gemspec
76
+ - lib/knicks_history.rb
77
+ - lib/knicks_history/cli.rb
78
+ - lib/knicks_history/scraper.rb
79
+ - lib/knicks_history/season.rb
80
+ - lib/knicks_history/version.rb
81
+ - spec.md
82
+ homepage: https://github.com/dkStephanos/KnicksHistoryCLI/tree/master/knicks_history
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.7.2
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: CLI App providing statistics for New York Knicks seasons.
106
+ test_files: []