Class: NbaDraft2017::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/nba_draft_2017/player.rb

Constant Summary collapse

@@all =
[]
@@nba_teams =
[]
@@former_teams =
[]
@@all_attributes =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#ageObject

Returns the value of attribute age.



3
4
5
# File 'lib/nba_draft_2017/player.rb', line 3

def age
  @age
end

#apgObject

Returns the value of attribute apg.



3
4
5
# File 'lib/nba_draft_2017/player.rb', line 3

def apg
  @apg
end

#bpgObject

Returns the value of attribute bpg.



3
4
5
# File 'lib/nba_draft_2017/player.rb', line 3

def bpg
  @bpg
end

#fgObject

Returns the value of attribute fg.



3
4
5
# File 'lib/nba_draft_2017/player.rb', line 3

def fg
  @fg
end

#first_nameObject

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_statusObject

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_teamObject

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

#ftObject

Returns the value of attribute ft.



3
4
5
# File 'lib/nba_draft_2017/player.rb', line 3

def ft
  @ft
end

#heightObject

Returns the value of attribute height.



3
4
5
# File 'lib/nba_draft_2017/player.rb', line 3

def height
  @height
end

#key_statsObject

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_nameObject

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

#mpgObject

Returns the value of attribute mpg.



3
4
5
# File 'lib/nba_draft_2017/player.rb', line 3

def mpg
  @mpg
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/nba_draft_2017/player.rb', line 3

def name
  @name
end

#nba_teamObject

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

#pickObject

Returns the value of attribute pick.



3
4
5
# File 'lib/nba_draft_2017/player.rb', line 3

def pick
  @pick
end

#positionObject

Returns the value of attribute position.



3
4
5
# File 'lib/nba_draft_2017/player.rb', line 3

def position
  @position
end

#ppgObject

Returns the value of attribute ppg.



3
4
5
# File 'lib/nba_draft_2017/player.rb', line 3

def ppg
  @ppg
end

#profile_urlObject

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

#roundObject

Returns the value of attribute round.



3
4
5
# File 'lib/nba_draft_2017/player.rb', line 3

def round
  @round
end

#rpgObject

Returns the value of attribute rpg.



3
4
5
# File 'lib/nba_draft_2017/player.rb', line 3

def rpg
  @rpg
end

#spgObject

Returns the value of attribute spg.



3
4
5
# File 'lib/nba_draft_2017/player.rb', line 3

def spg
  @spg
end

#threeObject

Returns the value of attribute three.



3
4
5
# File 'lib/nba_draft_2017/player.rb', line 3

def three
  @three
end

#tpgObject

Returns the value of attribute tpg.



3
4
5
# File 'lib/nba_draft_2017/player.rb', line 3

def tpg
  @tpg
end

#weightObject

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_playersObject



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

.allObject



97
98
99
# File 'lib/nba_draft_2017/player.rb', line 97

def self.all
  @@all
end

.all_attributesObject



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_teamsObject



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_teamsObject



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