Class: YFantasy::League

Inherits:
BaseResource show all
Defined in:
lib/y_fantasy/resources/league.rb,
lib/y_fantasy/resources/league/settings.rb,
lib/y_fantasy/resources/league/standings.rb,
lib/y_fantasy/resources/league/scoreboard.rb

Overview

Represents a Yahoo Fantasy League.

Defined Under Namespace

Classes: Scoreboard, Settings, Standings

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseResource

collection_name, dependent?, find, find_all, #key, resource_name

Methods included from Subresourceable

included

Instance Attribute Details

#allow_add_to_dl_extra_posBoolean (readonly)

Returns Whether the league allows adding extra positions to DL.

Returns:

  • (Boolean)

    Whether the league allows adding extra positions to DL



19
# File 'lib/y_fantasy/resources/league.rb', line 19

option :allow_add_to_dl_extra_pos, Types::Params::Bool

#current_weekInteger? (readonly)

Returns The current week number of the league.

Returns:

  • (Integer, nil)

    The current week number of the league



107
# File 'lib/y_fantasy/resources/league.rb', line 107

option :current_week, optional: true, type: Types::Coercible::Integer

#draft_resultsArray<DraftResult>? (readonly)

Returns The draft results for the league.

Returns:

  • (Array<DraftResult>, nil)

    The draft results for the league



125
# File 'lib/y_fantasy/resources/league.rb', line 125

option :draft_results, optional: true, type: array_of(DraftResult)

#draft_statusString (readonly)

Returns The status of the draft.

Returns:

  • (String)

    The status of the draft



23
# File 'lib/y_fantasy/resources/league.rb', line 23

option :draft_status

#edit_keyString (readonly)

Returns The edit key for this league.

Returns:

  • (String)

    The edit key for this league



27
# File 'lib/y_fantasy/resources/league.rb', line 27

option :edit_key

#end_dateDate (readonly)

Returns The end date of the league.

Returns:

  • (Date)

    The end date of the league



31
# File 'lib/y_fantasy/resources/league.rb', line 31

option :end_date, type: Types::Params::Date

#end_weekInteger? (readonly)

Returns The final week of the league.

Returns:

  • (Integer, nil)

    The final week of the league



115
# File 'lib/y_fantasy/resources/league.rb', line 115

option :end_week, optional: true, type: Types::Coercible::Integer

#felo_tierString (readonly)

Returns The Fantasy ELO tier of the league.

Returns:

  • (String)

    The Fantasy ELO tier of the league



35
# File 'lib/y_fantasy/resources/league.rb', line 35

option :felo_tier

#game_codeString (readonly)

Returns The game code (e.g. “nfl”, “nba”).

Returns:

  • (String)

    The game code (e.g. “nfl”, “nba”)



39
# File 'lib/y_fantasy/resources/league.rb', line 39

option :game_code

#is_cash_leagueBoolean (readonly)

Returns Whether this is a cash league.

Returns:

  • (Boolean)

    Whether this is a cash league



43
# File 'lib/y_fantasy/resources/league.rb', line 43

option :is_cash_league, Types::Params::Bool

#is_finishedBoolean? (readonly)

Returns Whether the league has finished.

Returns:

  • (Boolean, nil)

    Whether the league has finished



119
# File 'lib/y_fantasy/resources/league.rb', line 119

option :is_finished, optional: true, type: Types::Params::Bool

#is_pro_leagueBoolean (readonly)

Returns Whether this is a pro league.

Returns:

  • (Boolean)

    Whether this is a pro league



47
# File 'lib/y_fantasy/resources/league.rb', line 47

option :is_pro_league, Types::Params::Bool

#league_idString (readonly)

Returns The ID for this league.

Returns:

  • (String)

    The ID for this league



15
# File 'lib/y_fantasy/resources/league.rb', line 15

option :league_id

#league_keyString (readonly)

Returns The unique key for this league.

Returns:

  • (String)

    The unique key for this league



11
# File 'lib/y_fantasy/resources/league.rb', line 11

option :league_key

#league_typeString (readonly)

Returns The type of league.

Returns:

  • (String)

    The type of league



51
# File 'lib/y_fantasy/resources/league.rb', line 51

option :league_type

#league_update_timestampInteger (readonly)

Returns The timestamp of the last league update.

Returns:

  • (Integer)

    The timestamp of the last league update



55
# File 'lib/y_fantasy/resources/league.rb', line 55

option :league_update_timestamp, Types::Coercible::Integer

#logo_urlString (readonly)

Returns The URL for the league logo.

Returns:

  • (String)

    The URL for the league logo



59
# File 'lib/y_fantasy/resources/league.rb', line 59

option :logo_url

#nameString (readonly)

Returns The name of the league.

Returns:

  • (String)

    The name of the league



63
# File 'lib/y_fantasy/resources/league.rb', line 63

option :name

#num_teamsInteger (readonly)

Returns The number of teams in the league.

Returns:

  • (Integer)

    The number of teams in the league



67
# File 'lib/y_fantasy/resources/league.rb', line 67

option :num_teams, type: Types::Coercible::Integer

#playersArray<Player>? (readonly)

Returns The players in the league. By default, only 25 players are returned.

Returns:

  • (Array<Player>, nil)

    The players in the league. By default, only 25 players are returned.



129
# File 'lib/y_fantasy/resources/league.rb', line 129

option :players, optional: true, type: array_of(Player)

#renewString (readonly)

Returns Previous league ID in the format “<game_id>_<league_id>”.

Examples:

“123_111111”

Returns:

  • (String)

    Previous league ID in the format “<game_id>_<league_id>”



72
# File 'lib/y_fantasy/resources/league.rb', line 72

option :renew

#renewedString (readonly)

Returns Next league ID in the format “<game_id>_<league_id>”.

Examples:

“789_222222”

Returns:

  • (String)

    Next league ID in the format “<game_id>_<league_id>”



77
# File 'lib/y_fantasy/resources/league.rb', line 77

option :renewed

#scoreboardScoreboard? (readonly)

Returns The league scoreboard.

Returns:



133
# File 'lib/y_fantasy/resources/league.rb', line 133

option :scoreboard, optional: true, type: instance_of(Scoreboard)

#scoring_typeString (readonly)

Returns The scoring type of the league.

Returns:

  • (String)

    The scoring type of the league



81
# File 'lib/y_fantasy/resources/league.rb', line 81

option :scoring_type

#seasonString (readonly)

Returns The season year of the league.

Returns:

  • (String)

    The season year of the league



85
# File 'lib/y_fantasy/resources/league.rb', line 85

option :season

#settingsSettings? (readonly)

Returns The league settings.

Returns:

  • (Settings, nil)

    The league settings



137
# File 'lib/y_fantasy/resources/league.rb', line 137

option :settings, optional: true, type: instance_of(Settings)

#short_invitation_urlString? (readonly)

Returns The short URL for invitations to the league.

Returns:

  • (String, nil)

    The short URL for invitations to the league



103
# File 'lib/y_fantasy/resources/league.rb', line 103

option :short_invitation_url, optional: true

#standingsStandings? (readonly)

Returns The league standings.

Returns:



141
# File 'lib/y_fantasy/resources/league.rb', line 141

option :standings, optional: true, type: instance_of(Standings)

#start_dateDate (readonly)

Returns The start date of the league.

Returns:

  • (Date)

    The start date of the league



89
# File 'lib/y_fantasy/resources/league.rb', line 89

option :start_date, type: Types::Params::Date

#start_weekInteger? (readonly)

Returns The starting week of the league.

Returns:

  • (Integer, nil)

    The starting week of the league



111
# File 'lib/y_fantasy/resources/league.rb', line 111

option :start_week, optional: true, type: Types::Coercible::Integer

#teamsArray<Team>? (readonly)

Returns The teams in this league.

Returns:

  • (Array<Team>, nil)

    The teams in this league



145
# File 'lib/y_fantasy/resources/league.rb', line 145

option :teams, optional: true, type: array_of(Team)

#urlString (readonly)

Returns The URL to the league’s Yahoo Fantasy page.

Returns:

  • (String)

    The URL to the league’s Yahoo Fantasy page



93
# File 'lib/y_fantasy/resources/league.rb', line 93

option :url

#weekly_deadlineString (readonly)

Returns The weekly deadline type.

Returns:

  • (String)

    The weekly deadline type



97
# File 'lib/y_fantasy/resources/league.rb', line 97

option :weekly_deadline

Instance Method Details

#ended?Boolean

Whether the league has ended

Returns:

  • (Boolean)

    Whether the league has ended based on finished status or end date



164
165
166
# File 'lib/y_fantasy/resources/league.rb', line 164

def ended?
  is_finished || Date.today > end_date
end

#next_league_keyString?

Returns the key of the next/renewed league

Returns:

  • (String, nil)

    The key of the next/renewed league, if any



176
177
178
# File 'lib/y_fantasy/resources/league.rb', line 176

def next_league_key
  renewed&.split("_")&.join(".l.")
end

#previous_league_keyString?

Returns the key of the previous league

Returns:

  • (String, nil)

    The key of the previous league, if any



170
171
172
# File 'lib/y_fantasy/resources/league.rb', line 170

def previous_league_key
  renew&.split("_")&.join(".l.")
end

#scoreboard_for_week(week) ⇒ Scoreboard

Gets the scoreboard for a specific week

Parameters:

  • week (Integer)

    The week number to get the scoreboard for

Returns:

  • (Scoreboard)

    The scoreboard for the specified week



183
184
185
# File 'lib/y_fantasy/resources/league.rb', line 183

def scoreboard_for_week(week)
  @scoreboard = self.class.find(league_key, with: :scoreboard, week: week).scoreboard
end

#started?Boolean

Whether the league has started

Returns:

  • (Boolean)

    Whether the league has started based on the start date



158
159
160
# File 'lib/y_fantasy/resources/league.rb', line 158

def started?
  Date.today >= start_date
end