nba-stats 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff8b26c9529f427f4afdf28357b6935a132b8c76
4
- data.tar.gz: bf8c356ba645fd0d9de36cc914165a08771190e2
3
+ metadata.gz: 77fe915ee660f8d723ff533f725e222c34ebeed4
4
+ data.tar.gz: 36246b0af9b5d0095cd289a6e3653eea513ac1e4
5
5
  SHA512:
6
- metadata.gz: 08030467660a1c4adc947b3d61fd16728893ca704f0fc82bd644a580698964c50c21a01d3df0b51729f90c661f389fea0c5d321cd416ddd21f0a561c22644891
7
- data.tar.gz: e60c4b156fb650e5d56b17818701078312569da65163cbee572d3a45d141600adb81b7f76f0d6bc44470c4f1fdcb8a4feded5efd01e53c333d1cba4707e29e10
6
+ metadata.gz: 52be75b9d14722ea257eeddff435dbf01086aa14d56364d4c727577268892dfeb0da5f69887df5c7ac4a9ec1de4c196aef68fcb7a50d57d60fd8be992e2f4663
7
+ data.tar.gz: 9cefc1ecd4e4db91ce1bbafc28bc175dea2a769600b48bc5149320224413493dee629793173c10ddc6ed359157aefdfc3f3f6b8eb3cd533b2107111daa0ecc54
@@ -1,32 +1,50 @@
1
1
  class NbaStats::CLI
2
2
 
3
3
  def call
4
+ puts "Welcome to the NBA Stats CLI Gem"
4
5
  start
5
6
  end
6
7
 
7
8
  def start
8
- puts "Welcome to the NBA Stats CLI Gem"
9
+ puts "Input one of the team names below to load their roster."
10
+ puts "Input exit to leave this program."
9
11
  puts "Here's the list of current teams"
10
- make_teams
11
- NbaStats::Team.all.each do |team|
12
- puts team.name
13
- end
14
12
 
15
- choose_team
16
- choose_player
13
+ make_teams if NbaStats::Team.all.empty?
14
+
15
+ rows = [["Eastern Conference", "Western Conference"]]
16
+ west_teams = NbaStats::Team.western_names
17
+ east_teams = NbaStats::Team.eastern_names
17
18
 
18
- puts "Do you want to look up another player on this team? y/n"
19
- response = gets.strip
20
- while response == "y"
21
- choose_player
22
- puts "Do you want to look up another player on this team? y/n"
23
- response = gets.strip
19
+ i = 0
20
+ while i < 15
21
+ rows << [east_teams[i], west_teams[i]]
22
+ i += 1
24
23
  end
25
24
 
26
- puts "Do you want to look up another team? y/n"
27
- response = gets.strip
28
- if response == "y"
29
- start
25
+ team_table = Terminal::Table.new rows: rows
26
+ puts team_table
27
+
28
+ input = ""
29
+ while input != "exit"
30
+ puts "Input a team name to see their roster: "
31
+ input = gets.strip
32
+ if NbaStats::Team.team_names.include? input
33
+ display_roster(input)
34
+ puts "Input a player name to see their individual stats: "
35
+ input = gets.strip
36
+ while NbaStats::Player.player_names.include? input
37
+ display_player_stats(input)
38
+ puts "Input another player name from this team to see their stats."
39
+ puts "Or input change teams to see another team's roster."
40
+ input = gets.strip
41
+ if input == "change teams" || input == "change team"
42
+ start
43
+ elsif input == "exit"
44
+ break
45
+ end
46
+ end
47
+ end
30
48
  end
31
49
  end
32
50
 
@@ -35,15 +53,9 @@ class NbaStats::CLI
35
53
  NbaStats::Team.create_from_collection(teams_array)
36
54
  end
37
55
 
38
- def choose_team
39
- puts "Enter a team name to see their roster: "
40
- requested_team = gets.strip
41
- while !NbaStats::Team.team_names.include? requested_team
42
- puts "That team doesn't exist. Try again."
43
- requested_team = gets.strip
44
- end
56
+ def display_roster(requested_team)
45
57
  team = NbaStats::Team.all.detect {|team| team.name == requested_team}
46
- team.add_players
58
+ team.add_players if team.players.empty?
47
59
  puts team.name + " roster:"
48
60
  rows = [["Number", "Name", "Position", "Height", "Experience"]]
49
61
  team.players.each do |player|
@@ -53,13 +65,7 @@ class NbaStats::CLI
53
65
  puts roster_table
54
66
  end
55
67
 
56
- def choose_player
57
- puts "Enter a player name to see their individual stats: "
58
- requested_player = gets.strip
59
- while !NbaStats::Player.player_names.include? requested_player
60
- puts "That player isn't on this team. Try again."
61
- requested_player = gets.strip
62
- end
68
+ def display_player_stats(requested_player)
63
69
  player = NbaStats::Player.all.detect {|player| player.name == requested_player}
64
70
  stats_hash = NbaStats::Scraper.get_player_stats(player)
65
71
  player.add_player_stats(stats_hash)
@@ -2,6 +2,7 @@ class NbaStats::Player
2
2
  attr_accessor :name, :team, :number, :player_url, :position, :height, :experience, :points_pg, :assists_pg, :rebounds_pg, :blocks_pg, :steals_pg, :minutes_pg, :fg_percentage, :three_percentage, :ft_percentage
3
3
 
4
4
  @@all = []
5
+
5
6
  def initialize(player_hash)
6
7
  player_hash.each do |key, value|
7
8
  self.send("#{key}=", value)
@@ -4,18 +4,24 @@ class NbaStats::Scraper
4
4
  Nokogiri::HTML(open(url))
5
5
  end
6
6
 
7
- # Returns an array of hashes with current team names and links to 2015-16 team page
8
7
  def self.get_teams
9
- page = open_page("http://www.basketball-reference.com/teams")
10
- teams_array = []
11
- teams = page.css("table#active tr.full_table a")
8
+ page = open_page("http://www.basketball-reference.com/leagues/NBA_2016_standings.html")
9
+
10
+ east_teams = page.css("table#E_standings td a")
11
+ west_teams = page.css("table#W_standings td a")
12
+
13
+ assign_teams(west_teams, "West") + assign_teams(east_teams, "East")
14
+ end
15
+
16
+ def self.assign_teams(teams, conference)
17
+ assigned_teams = []
12
18
  teams.each do |team|
13
19
  name = team.text
14
- team_url = "http://www.basketball-reference.com"+ team["href"] + "2016.html"
15
- hash = {name: name, team_url: team_url}
16
- teams_array << hash
20
+ team_url = "http://www.basketball-reference.com"+ team["href"]
21
+ hash = {name: name, team_url: team_url, conference: conference}
22
+ assigned_teams << hash unless assigned_teams.include? hash
17
23
  end
18
- teams_array
24
+ assigned_teams
19
25
  end
20
26
 
21
27
  def self.get_roster(team)
@@ -1,6 +1,6 @@
1
1
  class NbaStats::Team
2
2
 
3
- attr_accessor :name, :team_url, :players
3
+ attr_accessor :name, :team_url, :players, :conference
4
4
 
5
5
  @@all = []
6
6
 
@@ -9,7 +9,7 @@ class NbaStats::Team
9
9
  self.send("#{key}=", value)
10
10
  end
11
11
  @players = []
12
- @@all << self
12
+ @@all << self unless @@all.include? self
13
13
  end
14
14
 
15
15
  def add_players
@@ -19,7 +19,7 @@ class NbaStats::Team
19
19
 
20
20
  def self.create_from_collection(teams_array)
21
21
  teams_array.each do |team|
22
- new_team = NbaStats::Team.new(team)
22
+ new_team = NbaStats::Team.new(team) unless @@all.include? team
23
23
  end
24
24
  end
25
25
 
@@ -31,4 +31,14 @@ class NbaStats::Team
31
31
  @@all.collect {|team| team.name }
32
32
  end
33
33
 
34
+ def self.western_names
35
+ west = @@all.select {|team| team.conference == "West"}
36
+ west.collect {|team| team.name}.sort
37
+ end
38
+
39
+ def self.eastern_names
40
+ east = @@all.select {|team| team.conference == "East"}
41
+ east.collect {|team| team.name}.sort
42
+ end
43
+
34
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nba-stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Barron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-07 00:00:00.000000000 Z
11
+ date: 2016-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -108,7 +108,7 @@ dependencies:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
110
  version: 1.5.2
111
- description: A command line interface for looking 2015-16 NBA player stats
111
+ description: A command line interface for looking up 2015-16 NBA player stats
112
112
  email: alexbarron@gmail.com
113
113
  executables:
114
114
  - nba-stats
@@ -122,7 +122,7 @@ files:
122
122
  - lib/nba_stats/player.rb
123
123
  - lib/nba_stats/scraper.rb
124
124
  - lib/nba_stats/team.rb
125
- homepage: http://rubygems.org/gems/nba-stats
125
+ homepage: https://github.com/alexbarron/nba-stats-cli-gem
126
126
  licenses:
127
127
  - MIT
128
128
  metadata: {}
@@ -145,5 +145,5 @@ rubyforge_project:
145
145
  rubygems_version: 2.4.8
146
146
  signing_key:
147
147
  specification_version: 4
148
- summary: NBA Stats
148
+ summary: Lookup NBA Player Stats
149
149
  test_files: []