class BestNbaPlayersS18::Players
Attributes
info[RW]
name[RW]
position[RW]
rank[RW]
statistics[RW]
team[RW]
trend[RW]
Public Class Methods
all()
click to toggle source
# File lib/best_nba_players_18/players.rb, line 6 def self.all @@all end
create_players_from_collection(collection)
click to toggle source
# File lib/best_nba_players_18/players.rb, line 17 def self.create_players_from_collection collection collection.each do |players| players.each {|infos_hash| new(infos_hash) } end end
find(input)
click to toggle source
# File lib/best_nba_players_18/players.rb, line 23 def self.find input all[input-1] end
find_group(index, by_input)
click to toggle source
# File lib/best_nba_players_18/players.rb, line 65 def self.find_group index, by_input group(by_input)[index-1] end
group(by_input)
click to toggle source
# File lib/best_nba_players_18/players.rb, line 59 def self.group by_input all.select do |player| player.trend == by_input end end
group_size(by_input)
click to toggle source
# File lib/best_nba_players_18/players.rb, line 69 def self.group_size by_input group(by_input).size end
new(infos_hash)
click to toggle source
# File lib/best_nba_players_18/players.rb, line 10 def initialize infos_hash infos_hash.each do |info, value| self.send("#{info}=",value) end @@all << self end
sort(input = 1)
click to toggle source
# File lib/best_nba_players_18/players.rb, line 27 def self.sort(input = 1) # choice = ["rank","name","position","team","AGE","PPG","RPG","APG","STL","FG","FT","THREEPT","BLK"] choices = ["rank","AGE","PPG","RPG","APG","THREEPT","BLK","FT"] by_input = choices[input-1] if input > 1 return sort_asc by_input, true if by_input == "AGE" return sort_desc by_input else return sort_asc by_input end end
sort_asc(by_input, stats = false)
click to toggle source
# File lib/best_nba_players_18/players.rb, line 39 def self.sort_asc by_input, stats = false if !stats all.sort! do |player1, player2| player1.send(by_input) <=> player2.send(by_input) end return by_input else all.sort! do |player1, player2| player1.send("statistics")[by_input.to_sym] <=> player2.send("statistics")[by_input.to_sym] end return ["statistics",by_input] end end
sort_desc(by_input, stats = false)
click to toggle source
# File lib/best_nba_players_18/players.rb, line 52 def self.sort_desc by_input, stats = false all.sort! do |player1, player2| player2.send("statistics")[by_input.to_sym] <=> player1.send("statistics")[by_input.to_sym] end return ["statistics",by_input] end