class Player

class Player for objects that each represent one player

Attributes

age[RW]

attr_accessors (macros for setter and getter methods) for different attribues of Player

blurb[RW]

attr_accessors (macros for setter and getter methods) for different attribues of Player

class_year[RW]

attr_accessors (macros for setter and getter methods) for different attribues of Player

height[RW]

attr_accessors (macros for setter and getter methods) for different attribues of Player

last_rank[RW]

attr_accessors (macros for setter and getter methods) for different attribues of Player

name[RW]

attr_accessors (macros for setter and getter methods) for different attribues of Player

position[RW]

attr_accessors (macros for setter and getter methods) for different attribues of Player

rank[RW]

attr_accessors (macros for setter and getter methods) for different attribues of Player

schoolclub[RW]

attr_accessors (macros for setter and getter methods) for different attribues of Player

weight[RW]

attr_accessors (macros for setter and getter methods) for different attribues of Player

Public Class Methods

add_players(playerarray) click to toggle source

iterate through an array of player hashes: for each player, instantiate a new Player instance

# File lib/player.rb, line 27
def self.add_players(playerarray)
  playerarray.each do |player_hash|
      self.new(player_hash)
  end
end
all() click to toggle source

return all Player elements

# File lib/player.rb, line 34
def self.all
  @@all
end
find_by_name(name) click to toggle source

return first player by name

# File lib/player.rb, line 39
def self.find_by_name(name)
  playr=@@all.find {|player| player.name.downcase.include?(name.downcase)}
  # binding.pry
  playr
end
find_by_posn(posn) click to toggle source

return an array of all players in the Player Class by a given position

# File lib/player.rb, line 52
def self.find_by_posn(posn)
  @@all.select {|player| player.position.include?(posn)}
end
find_by_sclub(sclub) click to toggle source

return an array of all players in the Player Class by school/club

# File lib/player.rb, line 46
def self.find_by_sclub(sclub)
  @@all.select {|player| player.schoolclub == sclub}
end
new(phashrow) click to toggle source

initialize a new instance of Player…reads in a player hash, creates a new instance

# File lib/player.rb, line 16
def initialize(phashrow)

  phashrow.each do |key, val|
    self.send("#{key}=", "#{val}")
  end
  # then shovels the instance into @@all
  @@all << self

end

Public Instance Methods

display_info() click to toggle source

displays detailed info for an instance of Player

# File lib/player.rb, line 56
def display_info
    
    puts "\nPlayer Name: #{self.name}"
    puts "Current Rank: #{self.rank}"
    puts "Position:  #{self.position}"
    puts "School/Club:  #{self.schoolclub}"
    # binding.pry
    #if there is no class_year, nothing is displayed
      puts "Year:  #{self.class_year}"
    #
    puts "Height/Weight:  #{self.height}, #{self.weight} "
    puts "Age: #{self.age}"
    puts "Last rank:  #{self.last_rank}"
    puts "Scouting Report: #{self.blurb}"
    puts "------------------------------------"
end