nba_information 0.1.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
+ SHA256:
3
+ metadata.gz: 3baea276998e37e586eaa84155ac7f2392ff6a25586525750474d8b71fbe7aea
4
+ data.tar.gz: 957c68a7c97564cda61e72b94f165205cb195c30b500f9947ee2a90f1eff9208
5
+ SHA512:
6
+ metadata.gz: cadd8c96d5d1da1aaddec7cb911631b7ba1bd38368de6cc34bb9917641a6b91a8ab79342865649b8375704f1b6fc80e90948ccf30b49b4468b08d94037238e83
7
+ data.tar.gz: 91c8010c43fb1ad334f960b96f544477cfa3fa56f77407f2cd97cb7772206fba46e93995e2c13bd4b84d62eb4dd54ca09f43c417aa48ff62b1114109f8655095
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
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 nba_info.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nba_info (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.1)
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
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler (~> 1.16)
25
+ nba_info!
26
+ pry
27
+ rake (~> 10.0)
28
+
29
+ BUNDLED WITH
30
+ 1.17.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 RSchaubeck
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,26 @@
1
+ NBA Info Gem
2
+
3
+ This is a CLI gem for the NBA. Check the current conference standings, view the schedule of games for today,
4
+ or view your favorite teams stats. All standings, stats, and schedules are updated in realtime.
5
+
6
+ ## Installation
7
+
8
+
9
+
10
+ ## Usage
11
+
12
+ TODO: Write usage instructions here
13
+
14
+ ## Development
15
+
16
+ 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.
17
+
18
+ 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).
19
+
20
+ ## Contributing
21
+
22
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nba_info.
23
+
24
+ ## License
25
+
26
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rubygems'
3
+ require 'bundler/setup'
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nba_info"
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/nba-info ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nba_info"
5
+
6
+ NbaInfo::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,100 @@
1
+ class NbaInfo::CLI
2
+
3
+ def call
4
+ instruct
5
+ input = gets.strip.capitalize
6
+ until input == "Exit"
7
+ case input
8
+ when "Commands"
9
+ instruct
10
+ input = gets.strip.capitalize
11
+ when "Key"
12
+ key
13
+ input = gets.strip.capitalize
14
+ when "Schedule"
15
+ schedule
16
+ input = gets.strip.capitalize
17
+ when "Standings"
18
+ standings
19
+ input = gets.strip.capitalize
20
+ when "Team"
21
+ team
22
+ input = gets.strip.capitalize
23
+ else
24
+ puts "Not a valid command"
25
+ input = gets.strip.capitalize
26
+ end
27
+ end
28
+ end
29
+
30
+ def instruct
31
+ puts <<-DOC.gsub /^\s*/, ''
32
+ Welcome to the NBA Info CLI gem!
33
+ List of commands:
34
+ commands - show these commands again
35
+ key - show meanings of the stat abbreviations
36
+ schedule - show todays schedule
37
+ standings - show current standings
38
+ team - get more info about a team
39
+ exit - exit program
40
+ DOC
41
+ end
42
+
43
+ def schedule
44
+ sched = NbaInfo::Scraper.scrape_schedule
45
+ puts "All times are Eastern Standard"
46
+ sched.each do |game|
47
+ puts "#{game[:away].ljust(4)} @ #{game[:home].ljust(4)} - #{game[:time]}"
48
+ end
49
+ ""
50
+ end
51
+
52
+ def standings
53
+ nba = NbaInfo::Team.add_stats
54
+ puts <<-DOC.gsub /^\s*/, ''
55
+ EASTERN CONFERENCE
56
+ Team |Record | GB
57
+ ----------------------------------------
58
+ DOC
59
+ nba[:east].each do |team|
60
+ puts "#{team.name.ljust(23)} #{team.record.ljust(9)} #{team.gb}"
61
+ end
62
+ puts <<-DOC.gsub /^\s*/, ''
63
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
64
+ WESTERN CONFERENCE
65
+ Team |Record | GB
66
+ ----------------------------------------
67
+ DOC
68
+ nba[:west].each do |team|
69
+ puts "#{team.name.ljust(23)} #{team.record.ljust(9)} #{team.gb}"
70
+ end
71
+ ""
72
+ end
73
+
74
+ def team
75
+ nba = NbaInfo::Team.add_stats
76
+ puts "Type the name of a team (omit the city from the search e.g. new york knicks would just be knicks)"
77
+ input = gets.strip.capitalize
78
+ if nba[:east].any?{|team| team.name.include?(input)}
79
+ team = nba[:east].detect{|t| t.name.include?(input)}
80
+ puts "#{team.name}(#{team.record}) -- PPG: #{team.ppg} -- OPP PPG: #{team.opp_ppg} -- L10: #{team.l_ten} -- Strk: #{team.streak}"
81
+ elsif nba[:west].any?{|team| team.name.include?(input)}
82
+ team = nba[:west].detect{|t| t.name.include?(input)}
83
+ puts "#{team.name}(#{team.record}) -- PPG: #{team.ppg} -- OPP PPG: #{team.opp_ppg} -- L10: #{team.l_ten} -- Strk: #{team.streak}"
84
+ else
85
+ "Make sure you omitted the city and spelled the team name correctly"
86
+ end
87
+ ""
88
+ end
89
+
90
+ def key
91
+ puts <<-DOC.gsub /^\s*/, ''
92
+ GB - games back
93
+ PPG - points per game
94
+ OPP PPG - opponents points per game
95
+ L10 - last 10
96
+ Strk - streak
97
+ DOC
98
+ end
99
+
100
+ end
@@ -0,0 +1,77 @@
1
+ class NbaInfo::Scraper
2
+
3
+ def self.scrape_team
4
+ html = open("http://www.espn.com/nba/standings")
5
+ doc = Nokogiri::HTML(html)
6
+ nba = {:east => [], :west => []}
7
+ names = doc.css('span.hide-mobile a')
8
+ names.each_with_index do |t, i|
9
+ if i < 15
10
+ nba[:east] << {
11
+ name: t.text,
12
+ place: i + 1
13
+ }
14
+ else
15
+ nba[:west] << {
16
+ name: t.text,
17
+ place: i - 14
18
+ }
19
+ end
20
+ end
21
+ nba
22
+ end
23
+
24
+ def self.scrape_stats
25
+ html = open("http://www.espn.com/nba/standings")
26
+ doc = Nokogiri::HTML(html)
27
+ nba = {:east => [], :west => []}
28
+ records = doc.css('table.Table2__table-scroller tbody.Table2__tbody tr')
29
+ records.each_with_index do |r, i|
30
+ wins = r.css('td:first-child span').text
31
+ loss = r.css('td:nth-child(2) span').text
32
+ record = "#{wins} - #{loss}"
33
+ gb = r.css('td:nth-child(4) span').text
34
+ ppg = r.css('td:nth-child(9) span').text
35
+ opp_ppg = r.css('td:nth-child(10) span').text
36
+ strk = r.css('td:nth-child(12) span').text
37
+ l_ten = r.css('td:last-child span').text
38
+ if i < 15
39
+ nba[:east] << {
40
+ record: record,
41
+ gb: gb,
42
+ ppg: ppg,
43
+ opp_ppg: opp_ppg,
44
+ streak: strk,
45
+ l_ten: l_ten
46
+ }
47
+ else
48
+ nba[:west] << {
49
+ record: record,
50
+ gb: gb,
51
+ ppg: ppg,
52
+ opp_ppg: opp_ppg,
53
+ streak: strk,
54
+ l_ten: l_ten
55
+ }
56
+ end
57
+ end
58
+ nba
59
+ end
60
+
61
+ def self.scrape_schedule
62
+ html = open("https://www.si.com/nba/schedule")
63
+ doc = Nokogiri::HTML(html)
64
+ schedule = []
65
+ games = doc.css('table')[0].css('tr:not(:first-child)')
66
+ games.each do |game|
67
+ schedule << {
68
+ away: game.css('td:first-child span.team-abbreviation')[0].text.gsub(/\s+/, ""),
69
+ home: game.css('td:nth-child(2) span.team-abbreviation')[0].text.gsub(/\s+/, ""),
70
+ time: game.css('td:nth-child(3)').text.strip
71
+ }
72
+ end
73
+ schedule
74
+ end
75
+
76
+
77
+ end
@@ -0,0 +1,56 @@
1
+ class NbaInfo::Team
2
+
3
+ attr_accessor :name, :place, :record, :gb, :streak, :ppg, :opp_ppg, :l_ten
4
+
5
+ @@nba = {:east => [], :west => []}
6
+
7
+ def initialize(team_hash)
8
+ team_hash.each do |key, val|
9
+ self.send "#{key}=", val
10
+ end
11
+ end
12
+
13
+ def self.create
14
+ nba = NbaInfo::Scraper.scrape_team
15
+ if @@nba[:east].empty? || @@nba[:west].empty?
16
+ nba[:east].each do |team|
17
+ t = self.new(team)
18
+ @@nba[:east] << t
19
+ end
20
+ nba[:west].each do |team|
21
+ t = self.new(team)
22
+ @@nba[:west] << t
23
+ end
24
+ end
25
+ @@nba
26
+ end
27
+
28
+ def self.add_stats
29
+ self.create
30
+ stats = NbaInfo::Scraper.scrape_stats
31
+ @@nba[:east].each_with_index do |team, i|
32
+ stats[:east][i].each do |key, val|
33
+ team.send "#{key}=", val
34
+ end
35
+ end
36
+ @@nba[:west].each_with_index do |team, i|
37
+ stats[:west][i].each do |key, val|
38
+ team.send "#{key}=", val
39
+ end
40
+ end
41
+ @@nba
42
+ end
43
+
44
+ def all
45
+ @@nba
46
+ end
47
+
48
+ def east
49
+ @@nba[:east]
50
+ end
51
+
52
+ def west
53
+ @@nba[:west]
54
+ end
55
+
56
+ end
@@ -0,0 +1,3 @@
1
+ module NbaInfo
2
+ VERSION = "0.1.0"
3
+ end
data/lib/nba_info.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+ require 'pry'
4
+
5
+ require_relative "./nba_info/version"
6
+ require_relative "./nba_info/cli"
7
+ require_relative "./nba_info/team"
8
+ require_relative "./nba_info/scraper"
data/nba_info.gemspec ADDED
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "nba_info/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nba_information"
8
+ spec.version = NbaInfo::VERSION
9
+ spec.authors = ["RSchaubeck"]
10
+ spec.email = ["richard.schaubeck@gmail.com"]
11
+
12
+ spec.summary = "nba info"
13
+ spec.description =
14
+ spec.homepage = "https://github.com/RSchaubeck/nba-info-gem"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "pry"
29
+
30
+ spec.add_dependency "nokogiri"
31
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nba_information
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - RSchaubeck
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-25 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'
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: https://github.com/RSchaubeck/nba-info-gem
70
+ email:
71
+ - richard.schaubeck@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/nba-info
84
+ - bin/setup
85
+ - lib/nba_info.rb
86
+ - lib/nba_info/cli.rb
87
+ - lib/nba_info/scraper.rb
88
+ - lib/nba_info/team.rb
89
+ - lib/nba_info/version.rb
90
+ - nba_info.gemspec
91
+ homepage: https://github.com/RSchaubeck/nba-info-gem
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubygems_version: 3.0.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: nba info
114
+ test_files: []