class Player
class Player
for objects that each represent one player
Attributes
attr_accessors (macros for setter and getter methods) for different attribues of Player
attr_accessors (macros for setter and getter methods) for different attribues of Player
attr_accessors (macros for setter and getter methods) for different attribues of Player
attr_accessors (macros for setter and getter methods) for different attribues of Player
attr_accessors (macros for setter and getter methods) for different attribues of Player
attr_accessors (macros for setter and getter methods) for different attribues of Player
attr_accessors (macros for setter and getter methods) for different attribues of Player
attr_accessors (macros for setter and getter methods) for different attribues of Player
attr_accessors (macros for setter and getter methods) for different attribues of Player
attr_accessors (macros for setter and getter methods) for different attribues of Player
Public Class Methods
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
return all Player
elements
# File lib/player.rb, line 34 def self.all @@all end
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
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
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
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
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