Class: ESPNNBAFantasy::League
- Inherits:
-
Object
- Object
- ESPNNBAFantasy::League
- Includes:
- PlayerFinder
- Defined in:
- lib/espn_nba_fantasy/league.rb
Instance Attribute Summary collapse
-
#current_end_year ⇒ Object
Returns the value of attribute current_end_year.
-
#current_start_year ⇒ Object
Returns the value of attribute current_start_year.
-
#league_id ⇒ Object
Returns the value of attribute league_id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#stat_data ⇒ Object
Returns the value of attribute stat_data.
-
#teams ⇒ Object
Returns the value of attribute teams.
-
#users ⇒ Object
Returns the value of attribute users.
Instance Method Summary collapse
-
#findplayer(team_name, str) ⇒ Object
pull up a Player object based on their name and their team.
-
#initialize(league_id, year, s2, sw) ⇒ League
constructor
initializes the league.
-
#team_list ⇒ Object
gives you an array of each team’s name and id in the league.
- #to_s ⇒ Object
Methods included from PlayerFinder
Constructor Details
#initialize(league_id, year, s2, sw) ⇒ League
initializes the league
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/espn_nba_fantasy/league.rb', line 17 def initialize(league_id, year, s2, sw) @uri = "https://lm-api-reads.fantasy.espn.com/apis/v3/games/fba/seasons/#{year}/segments/0/leagues/#{league_id}?view=mRoster&view=mSettings&view=mTeam&view=modular&view=mNav" @cookies = {'espn_s2': "#{s2}", 'SWID': "#{sw}"} @data = JSON.parse(RestClient.get(@uri, {cookies: @cookies})) @teams = make_team_objects @users = make_user_objects @stat_data = make_stat_data @league_id = @data['id'] @name = @data['settings']['name'] @current_start_year = @data['seasonId'] @current_end_year = @current_start_year + 1 end |
Instance Attribute Details
#current_end_year ⇒ Object
Returns the value of attribute current_end_year.
13 14 15 |
# File 'lib/espn_nba_fantasy/league.rb', line 13 def current_end_year @current_end_year end |
#current_start_year ⇒ Object
Returns the value of attribute current_start_year.
13 14 15 |
# File 'lib/espn_nba_fantasy/league.rb', line 13 def current_start_year @current_start_year end |
#league_id ⇒ Object
Returns the value of attribute league_id.
13 14 15 |
# File 'lib/espn_nba_fantasy/league.rb', line 13 def league_id @league_id end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/espn_nba_fantasy/league.rb', line 13 def name @name end |
#stat_data ⇒ Object
Returns the value of attribute stat_data.
13 14 15 |
# File 'lib/espn_nba_fantasy/league.rb', line 13 def stat_data @stat_data end |
#teams ⇒ Object
Returns the value of attribute teams.
13 14 15 |
# File 'lib/espn_nba_fantasy/league.rb', line 13 def teams @teams end |
#users ⇒ Object
Returns the value of attribute users.
13 14 15 |
# File 'lib/espn_nba_fantasy/league.rb', line 13 def users @users end |
Instance Method Details
#findplayer(team_name, str) ⇒ Object
pull up a Player object based on their name and their team
42 43 44 45 46 47 |
# File 'lib/espn_nba_fantasy/league.rb', line 42 def findplayer(team_name, str) team = @teams.select{|t| t.name == team_name}.first return "No team named #{team_name}" unless team find_players(team.players, str) || "#{str} cannot be found in #{team_name}'s roster" end |
#team_list ⇒ Object
gives you an array of each team’s name and id in the league
36 37 38 |
# File 'lib/espn_nba_fantasy/league.rb', line 36 def team_list @teams.map{|r| [r.name, r.team_id]} end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/espn_nba_fantasy/league.rb', line 30 def to_s "League #{@league_id}" end |