Class: NbaDraft2017::Player
- Inherits:
-
Object
- Object
- NbaDraft2017::Player
- Defined in:
- lib/nba_draft_2017/player.rb
Constant Summary collapse
- @@all =
[]
- @@nba_teams =
[]
- @@former_teams =
[]
- @@all_attributes =
nil
Instance Attribute Summary collapse
-
#age ⇒ Object
Returns the value of attribute age.
-
#apg ⇒ Object
Returns the value of attribute apg.
-
#bpg ⇒ Object
Returns the value of attribute bpg.
-
#fg ⇒ Object
Returns the value of attribute fg.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#former_status ⇒ Object
Returns the value of attribute former_status.
-
#former_team ⇒ Object
Returns the value of attribute former_team.
-
#ft ⇒ Object
Returns the value of attribute ft.
-
#height ⇒ Object
Returns the value of attribute height.
-
#key_stats ⇒ Object
Returns the value of attribute key_stats.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#mpg ⇒ Object
Returns the value of attribute mpg.
-
#name ⇒ Object
Returns the value of attribute name.
-
#nba_team ⇒ Object
Returns the value of attribute nba_team.
-
#pick ⇒ Object
Returns the value of attribute pick.
-
#position ⇒ Object
Returns the value of attribute position.
-
#ppg ⇒ Object
Returns the value of attribute ppg.
-
#profile_url ⇒ Object
Returns the value of attribute profile_url.
-
#round ⇒ Object
Returns the value of attribute round.
-
#rpg ⇒ Object
Returns the value of attribute rpg.
-
#spg ⇒ Object
Returns the value of attribute spg.
-
#three ⇒ Object
Returns the value of attribute three.
-
#tpg ⇒ Object
Returns the value of attribute tpg.
-
#weight ⇒ Object
Returns the value of attribute weight.
Class Method Summary collapse
- .add_attributes_to_player(player) ⇒ Object
- .add_attributes_to_players ⇒ Object
- .all ⇒ Object
- .all_attributes ⇒ Object
- .find_player_by_name(player_name) ⇒ Object
- .find_player_by_pick(pick) ⇒ Object
- .former_teams ⇒ Object
- .nba_teams ⇒ Object
- .players_by_former_team(former_team) ⇒ Object
- .players_by_nba_team(nba_team) ⇒ Object
- .stat_greater_than(stat_category, stat_num) ⇒ Object
Instance Method Summary collapse
- #add_player_attributes(attributes_hash) ⇒ Object
-
#initialize(player_hash) ⇒ Player
constructor
A new instance of Player.
Constructor Details
#initialize(player_hash) ⇒ Player
Returns a new instance of Player.
11 12 13 14 |
# File 'lib/nba_draft_2017/player.rb', line 11 def initialize(player_hash) player_hash.each {|attribute, value| self.send("#{attribute}=", value) } @@all << self end |
Instance Attribute Details
#age ⇒ Object
Returns the value of attribute age.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def age @age end |
#apg ⇒ Object
Returns the value of attribute apg.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def apg @apg end |
#bpg ⇒ Object
Returns the value of attribute bpg.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def bpg @bpg end |
#fg ⇒ Object
Returns the value of attribute fg.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def fg @fg end |
#first_name ⇒ Object
Returns the value of attribute first_name.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def first_name @first_name end |
#former_status ⇒ Object
Returns the value of attribute former_status.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def former_status @former_status end |
#former_team ⇒ Object
Returns the value of attribute former_team.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def former_team @former_team end |
#ft ⇒ Object
Returns the value of attribute ft.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def ft @ft end |
#height ⇒ Object
Returns the value of attribute height.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def height @height end |
#key_stats ⇒ Object
Returns the value of attribute key_stats.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def key_stats @key_stats end |
#last_name ⇒ Object
Returns the value of attribute last_name.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def last_name @last_name end |
#mpg ⇒ Object
Returns the value of attribute mpg.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def mpg @mpg end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def name @name end |
#nba_team ⇒ Object
Returns the value of attribute nba_team.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def nba_team @nba_team end |
#pick ⇒ Object
Returns the value of attribute pick.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def pick @pick end |
#position ⇒ Object
Returns the value of attribute position.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def position @position end |
#ppg ⇒ Object
Returns the value of attribute ppg.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def ppg @ppg end |
#profile_url ⇒ Object
Returns the value of attribute profile_url.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def profile_url @profile_url end |
#round ⇒ Object
Returns the value of attribute round.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def round @round end |
#rpg ⇒ Object
Returns the value of attribute rpg.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def rpg @rpg end |
#spg ⇒ Object
Returns the value of attribute spg.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def spg @spg end |
#three ⇒ Object
Returns the value of attribute three.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def three @three end |
#tpg ⇒ Object
Returns the value of attribute tpg.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def tpg @tpg end |
#weight ⇒ Object
Returns the value of attribute weight.
3 4 5 |
# File 'lib/nba_draft_2017/player.rb', line 3 def weight @weight end |
Class Method Details
.add_attributes_to_player(player) ⇒ Object
29 30 31 32 33 |
# File 'lib/nba_draft_2017/player.rb', line 29 def self.add_attributes_to_player(player) attributes = NbaDraft2017::Scraper.scrape_player("http://www.nba.com/draft/2017/prospects/" + player.profile_url) player.add_player_attributes(attributes) player end |
.add_attributes_to_players ⇒ Object
35 36 37 38 39 |
# File 'lib/nba_draft_2017/player.rb', line 35 def self.add_attributes_to_players @@all_attributes = self.all.each do |player| add_attributes_to_player(player) end end |
.all ⇒ Object
97 98 99 |
# File 'lib/nba_draft_2017/player.rb', line 97 def self.all @@all end |
.all_attributes ⇒ Object
93 94 95 |
# File 'lib/nba_draft_2017/player.rb', line 93 def self.all_attributes @@all_attributes end |
.find_player_by_name(player_name) ⇒ Object
20 21 22 |
# File 'lib/nba_draft_2017/player.rb', line 20 def self.find_player_by_name(player_name) NbaDraft2017::Player.all.detect { |player| player.name.downcase == player_name.downcase } end |
.find_player_by_pick(pick) ⇒ Object
24 25 26 |
# File 'lib/nba_draft_2017/player.rb', line 24 def self.find_player_by_pick(pick) NbaDraft2017::Player.all.detect { |player| player.pick == pick.to_s } end |
.former_teams ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/nba_draft_2017/player.rb', line 75 def self.former_teams self.all.each do |player| @@former_teams << player.former_team.downcase.strip end @@former_teams.uniq end |
.nba_teams ⇒ Object
58 59 60 61 62 63 |
# File 'lib/nba_draft_2017/player.rb', line 58 def self.nba_teams self.all.each do |player| @@nba_teams << player.nba_team.downcase.strip end @@nba_teams.uniq end |
.players_by_former_team(former_team) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/nba_draft_2017/player.rb', line 83 def self.players_by_former_team(former_team) puts former_team.upcase.bold.colorize(:green) self.all.each do |player| if player.former_team.downcase == former_team.downcase puts "Rd: ".colorize(:red) +"#{player.round}" + " Pick: ".colorize(:red) +"#{player.pick} #{player.name.upcase.bold.colorize(:blue)} to #{player.nba_team.bold.colorize(:blue)}" end end end |
.players_by_nba_team(nba_team) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/nba_draft_2017/player.rb', line 65 def self.players_by_nba_team(nba_team) puts nba_team.upcase.bold.colorize(:green) self.all.each do |player| if player.nba_team.downcase == nba_team.downcase puts "Rd: ".colorize(:red) +"#{player.round}" + " Pick: ".colorize(:red) +"#{player.pick} #{player.name.upcase.bold.colorize(:blue)} from #{player.former_team.bold.colorize(:blue)}" end end end |
.stat_greater_than(stat_category, stat_num) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/nba_draft_2017/player.rb', line 42 def self.stat_greater_than(stat_category, stat_num) @@all_attributes ||= self.add_attributes_to_players puts "Players with a higher #{stat_category} average than #{stat_num.to_f} include:".colorize(:green) puts "------------------------------------------------------------".bold.colorize(:red) players = self.all.select.with_index(1) do |player, idx| if player.send(stat_category) && player.send(stat_category) > stat_num.to_f puts "Pick: #{idx.to_s.colorize(:green)}. #{player.name.colorize(:green)} - #{player.send(stat_category).to_s.colorize(:red)} #{stat_category}" player end end puts "Nobody!".bold.colorize(:red) if players.empty? puts "------------------------------------------------------------".bold.colorize(:red) end |
Instance Method Details
#add_player_attributes(attributes_hash) ⇒ Object
16 17 18 |
# File 'lib/nba_draft_2017/player.rb', line 16 def add_player_attributes(attributes_hash) attributes_hash.each { |attribute, value| self.send("#{attribute}=", value) } end |