nba-stats 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ac2154b740552370d6d0dfebb632ccb7a9f46e6
4
- data.tar.gz: 953eb7e370dfeb946cdd6dfb043e40b886037979
3
+ metadata.gz: e43371a99a71996e7735c6e5c2fd02912bc8a00f
4
+ data.tar.gz: 03a7804220468aafb1ec96a3e7d93c903add0b33
5
5
  SHA512:
6
- metadata.gz: 46231e69e73e79c36738fa5083b0627cc061e125b489f59d253c74bf4b7623208af5a4e2d2a68d915ee7fde75c356efed71ae8d6acf1008e1b46d3155e9702e9
7
- data.tar.gz: e66a99f593616322a37a6cc5520e42e91b7cccb359ade4c27e7972d77caef0a14742ae26324781fba58252dfbcaacd6f2cb326980789a3e5d918579a06fa322f
6
+ metadata.gz: e00aece67b40ab210427da70d05aecb1914983126fe1ed95c287d0c41975be3ac4dc6b80eea60e202b671ceb0257aa55631d195715808666f4e479c778109b52
7
+ data.tar.gz: 80074837c175dcd034201eeb9104bdd5076bd425767ba2c417d4d40f391cef44fd0404b4cce9636846c89a80129e00432edff0b451367011d16384ccbfcaa893
@@ -10,20 +10,7 @@ class NbaStats::CLI
10
10
  puts "Input exit to leave this program."
11
11
  puts "Here's the list of current teams"
12
12
 
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
18
-
19
- i = 0
20
- while i < 15
21
- rows << [east_teams[i], west_teams[i]]
22
- i += 1
23
- end
24
-
25
- team_table = Terminal::Table.new rows: rows
26
- puts team_table
13
+ display_teams
27
14
 
28
15
  input = ""
29
16
  while input != "exit"
@@ -52,27 +39,47 @@ class NbaStats::CLI
52
39
  NbaStats::Team.create_from_collection(teams_array)
53
40
  end
54
41
 
42
+ def display_teams
43
+ make_teams if NbaStats::Team.all.empty?
44
+
45
+ rows = [["Eastern Conference", "Western Conference"]]
46
+ west_teams = NbaStats::Team.western_names
47
+ east_teams = NbaStats::Team.eastern_names
48
+
49
+ i = 0
50
+ while i < 15
51
+ rows << [east_teams[i], west_teams[i]]
52
+ i += 1
53
+ end
54
+
55
+ puts Terminal::Table.new rows: rows
56
+ end
57
+
55
58
  def display_roster(requested_team)
56
59
  team = NbaStats::Team.all.detect {|team| team.name == requested_team}
60
+
57
61
  team.add_players if team.players.empty?
62
+
58
63
  puts team.name + " roster:"
64
+
59
65
  rows = [["Number", "Name", "Position", "Height", "Experience"]]
60
66
  team.players.each do |player|
61
67
  rows << [player.number, player.name, player.position, player.height, player.experience]
62
68
  end
63
- roster_table = Terminal::Table.new rows: rows
64
- puts roster_table
69
+
70
+ puts Terminal::Table.new rows: rows
65
71
  end
66
72
 
67
73
  def display_player_stats(requested_player)
68
74
  player = NbaStats::Player.all.detect {|player| player.name == requested_player}
69
- stats_hash = NbaStats::Scraper.get_player_stats(player)
70
- player.add_player_stats(stats_hash)
75
+
76
+ player.add_player_stats
77
+
71
78
  rows = [["Points/Game", "Assists/Game", "Rebounds/Game", "Blocks/Game", "Steals/Game", "FG%", "3P%", "FT%", "Minutes/Game",]]
72
79
  rows << [player.points_pg, player.assists_pg, player.rebounds_pg, player.blocks_pg, player.steals_pg, player.fg_percentage, player.three_percentage, player.ft_percentage, player.minutes_pg]
80
+
73
81
  puts "Here are #{player.name}'s 2015-16 stats: "
74
- stats_table = Terminal::Table.new rows: rows
75
- puts stats_table
82
+ puts Terminal::Table.new rows: rows
76
83
  end
77
84
 
78
85
  end
@@ -24,7 +24,8 @@ class NbaStats::Player
24
24
  end
25
25
  end
26
26
 
27
- def add_player_stats(stats_hash)
27
+ def add_player_stats
28
+ stats_hash = NbaStats::Scraper.get_player_stats(self)
28
29
  stats_hash.each do |key,value|
29
30
  self.send("#{key}=", value)
30
31
  end
@@ -17,7 +17,7 @@ class NbaStats::Scraper
17
17
  assigned_teams = []
18
18
  teams.each do |team|
19
19
  name = team.text
20
- team_url = "http://www.basketball-reference.com"+ team["href"]
20
+ team_url = "http://www.basketball-reference.com" + team["href"]
21
21
  hash = {name: name, team_url: team_url, conference: conference}
22
22
  assigned_teams << hash unless assigned_teams.include? hash
23
23
  end
@@ -35,11 +35,7 @@ class NbaStats::Scraper
35
35
  position = data_array[3]
36
36
  height = data_array[4]
37
37
  data_array[8] == "R" ? experience = "Rookie" : experience = data_array[8] + " Years"
38
-
39
- #Below is messy workaround
40
- #Cleaner player.css("a").first["href"] works outside of .each loop, but returns "undefined method '[]' for nil" inside .each
41
- player_url = player.css("a").map {|element| element["href"]}.first
42
- player_url = "http://www.basketball-reference.com" + player_url.to_s
38
+ player_url = "http://www.basketball-reference.com" + player.css("a").first["href"]
43
39
 
44
40
  hash = {name: name, number: number, position: position, height: height, experience: experience, player_url: player_url}
45
41
  players_array << hash
@@ -51,18 +47,17 @@ class NbaStats::Scraper
51
47
  page = open_page(player.player_url)
52
48
 
53
49
  season = page.css("table#per_game tr.full_table").last
54
- stats_array = season.text.gsub("\n", "").strip.split(" ")
55
-
50
+ stats_array = season.text.split("\n").map {|x| x.strip}
56
51
  stats_hash = {
57
- points_pg: stats_array[29],
58
- assists_pg: stats_array[24],
59
- rebounds_pg: stats_array[23],
60
- blocks_pg: stats_array[26],
61
- steals_pg: stats_array[25],
62
- minutes_pg: stats_array[7],
63
- fg_percentage: stats_array[10],
64
- three_percentage: stats_array[13],
65
- ft_percentage: stats_array[20]
52
+ points_pg: stats_array[30],
53
+ assists_pg: stats_array[25],
54
+ rebounds_pg: stats_array[24],
55
+ blocks_pg: stats_array[27],
56
+ steals_pg: stats_array[26],
57
+ minutes_pg: stats_array[8],
58
+ fg_percentage: stats_array[11],
59
+ three_percentage: stats_array[14],
60
+ ft_percentage: stats_array[21]
66
61
  }
67
62
 
68
63
  end
@@ -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) unless @@all.include? team
22
+ new_team = NbaStats::Team.new(team)
23
23
  end
24
24
  end
25
25
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nba-stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Barron