Class: ESPNNBAFantasy::Team
- Inherits:
-
Object
- Object
- ESPNNBAFantasy::Team
- Includes:
- CalculateStats, PlayerFinder
- Defined in:
- lib/espn_nba_fantasy/team.rb
Instance Attribute Summary collapse
-
#league ⇒ Object
Returns the value of attribute league.
-
#name ⇒ Object
Returns the value of attribute name.
-
#players ⇒ Object
Returns the value of attribute players.
-
#roster ⇒ Object
Returns the value of attribute roster.
-
#team_id ⇒ Object
Returns the value of attribute team_id.
-
#teamstats ⇒ Object
Returns the value of attribute teamstats.
Instance Method Summary collapse
-
#initialize(obj, league) ⇒ Team
constructor
basic initialization with the various attributes.
-
#to_s ⇒ Object
returns data including the players trading away and receiving, your stats before and after the trade, and your change in stats for each category.
- #trade_players(to_trade = [], to_receive = [], other_team_name) ⇒ Object
Methods included from PlayerFinder
Methods included from CalculateStats
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
#league ⇒ Object
Returns the value of attribute league.
12 13 14 |
# File 'lib/espn_nba_fantasy/team.rb', line 12 def league @league end |
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'lib/espn_nba_fantasy/team.rb', line 12 def name @name end |
#players ⇒ Object
Returns the value of attribute players.
12 13 14 |
# File 'lib/espn_nba_fantasy/team.rb', line 12 def players @players end |
#roster ⇒ Object
Returns the value of attribute roster.
12 13 14 |
# File 'lib/espn_nba_fantasy/team.rb', line 12 def roster @roster end |
#team_id ⇒ Object
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 |
#teamstats ⇒ Object
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_s ⇒ Object
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 |