Class: ESPNNBAFantasy::Team

Inherits:
Object
  • Object
show all
Includes:
CalculateStats, PlayerFinder
Defined in:
lib/espn_nba_fantasy/team.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PlayerFinder

#find_players

Methods included from CalculateStats

#add_calculated_stats

Constructor Details

#initialize(obj, league) ⇒ Team

basic initialization with the various attributes



16
17
18
19
20
21
22
23
# File 'lib/espn_nba_fantasy/team.rb', line 16

def initialize(obj, league)
  @name = obj['name']
  @team_id = obj['id']
  @players = roster_maker(obj)
  @roster = roster_names
  @teamstats = make_team_stats(@players)
  @league = league
end

Instance Attribute Details

#leagueObject

Returns the value of attribute league.



12
13
14
# File 'lib/espn_nba_fantasy/team.rb', line 12

def league
  @league
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/espn_nba_fantasy/team.rb', line 12

def name
  @name
end

#playersObject

Returns the value of attribute players.



12
13
14
# File 'lib/espn_nba_fantasy/team.rb', line 12

def players
  @players
end

#rosterObject

Returns the value of attribute roster.



12
13
14
# File 'lib/espn_nba_fantasy/team.rb', line 12

def roster
  @roster
end

#team_idObject

Returns the value of attribute team_id.



12
13
14
# File 'lib/espn_nba_fantasy/team.rb', line 12

def team_id
  @team_id
end

#teamstatsObject

Returns the value of attribute teamstats.



12
13
14
# File 'lib/espn_nba_fantasy/team.rb', line 12

def teamstats
  @teamstats
end

Instance Method Details

#to_sObject

returns data including the players trading away and receiving, your stats before and after the trade, and your change in stats for each category



31
32
33
# File 'lib/espn_nba_fantasy/team.rb', line 31

def to_s
  "Team Name: #{name} | Roster: #{roster_names}"
end

#trade_players(to_trade = [], to_receive = [], other_team_name) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/espn_nba_fantasy/team.rb', line 35

def trade_players(to_trade = [], to_receive = [], other_team_name)
  other_team = league.teams.select{|team| team.name == other_team_name}.first
  return "No team named #{other_team_name}" unless other_team
  own_players = to_trade.map{|player| find_players(players, player)}
  other_players = to_receive.map{|player| find_players(other_team.players, player)}
  return "This trade included players not one of the specified teams" if (own_players.include?(nil)|| other_players.include?(nil))
  {'Trading:' => own_players.map{|p| p.full_name}, 
  'Receiving:' => other_players.map{|p| p.full_name}}.merge(new_team_stats(own_players, other_players))
  
end