Class: YFantasy::Game

Inherits:
BaseResource show all
Defined in:
lib/y_fantasy/resources/game.rb,
lib/y_fantasy/resources/game/game_week.rb,
lib/y_fantasy/resources/game/position_type.rb

Overview

Represents a Yahoo Fantasy Game (e.g. NFL, NBA, MLB). A game is the top-level sports resource and contains leagues, which contain teams.

Examples:

Get NFL game information with game weeks

games = YFantasy::Game.find_all_by_code('nfl', with: [:game_weeks])

See Also:

Defined Under Namespace

Classes: GameWeek, PositionType

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from BaseResource

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

Methods included from Subresourceable

included

Instance Attribute Details

#codeString (readonly)

Returns The general code for this game (eg. “nfl”, “nba”).

Returns:

  • (String)

    The general code for this game (eg. “nfl”, “nba”)



30
# File 'lib/y_fantasy/resources/game.rb', line 30

option :code

#current_weekInteger? (readonly)

Returns The current week number of the game.

Returns:

  • (Integer, nil)

    The current week number of the game



60
# File 'lib/y_fantasy/resources/game.rb', line 60

option :current_week, optional: true

#game_idString (readonly)

Returns The ID for this game (for Game resource, this is the same as game_key).

Returns:

  • (String)

    The ID for this game (for Game resource, this is the same as game_key)



22
# File 'lib/y_fantasy/resources/game.rb', line 22

option :game_id

#game_keyString (readonly)

Returns The unique key for this game.

Returns:

  • (String)

    The unique key for this game



18
# File 'lib/y_fantasy/resources/game.rb', line 18

option :game_key

#game_weeksArray<GameWeek>? (readonly)

Returns Array of game weeks for this game.

Returns:

  • (Array<GameWeek>, nil)

    Array of game weeks for this game



78
# File 'lib/y_fantasy/resources/game.rb', line 78

option :game_weeks, optional: true, type: array_of(GameWeek)

#groupsArray<Group>? (readonly)

Returns Array of groups for this game (e.g. NFL Survival).

Returns:

  • (Array<Group>, nil)

    Array of groups for this game (e.g. NFL Survival)



94
# File 'lib/y_fantasy/resources/game.rb', line 94

option :groups, optional: true, type: array_of(Group)

#has_scheduleBoolean? (readonly)

Returns Whether this game has a schedule.

Returns:

  • (Boolean, nil)

    Whether this game has a schedule



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

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

#is_contest_overBoolean? (readonly)

Returns Whether the contest is over.

Returns:

  • (Boolean, nil)

    Whether the contest is over



68
# File 'lib/y_fantasy/resources/game.rb', line 68

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

#is_contest_reg_activeBoolean? (readonly)

Returns Whether contest registration is active.

Returns:

  • (Boolean, nil)

    Whether contest registration is active



64
# File 'lib/y_fantasy/resources/game.rb', line 64

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

#is_game_overBoolean (readonly)

Returns Whether this game’s season is over.

Returns:

  • (Boolean)

    Whether this game’s season is over



50
# File 'lib/y_fantasy/resources/game.rb', line 50

option :is_game_over, type: Types::Params::Bool

#is_offseasonBoolean (readonly)

Returns Whether this game is in the offseason.

Returns:

  • (Boolean)

    Whether this game is in the offseason



54
# File 'lib/y_fantasy/resources/game.rb', line 54

option :is_offseason, type: Types::Params::Bool

#is_registration_overBoolean (readonly)

Returns Whether registration for this game is over.

Returns:

  • (Boolean)

    Whether registration for this game is over



46
# File 'lib/y_fantasy/resources/game.rb', line 46

option :is_registration_over, type: Types::Params::Bool

#leaguesArray<League>? (readonly)

Returns Array of leagues belonging to this game.

Returns:

  • (Array<League>, nil)

    Array of leagues belonging to this game



98
# File 'lib/y_fantasy/resources/game.rb', line 98

option :leagues, optional: true, type: array_of(League)

#nameString (readonly)

Returns The name of the game (eg. “Football”, “Baseball”).

Returns:

  • (String)

    The name of the game (eg. “Football”, “Baseball”)



26
# File 'lib/y_fantasy/resources/game.rb', line 26

option :name

#position_typesArray<PositionType>? (readonly)

Returns Array of position types for this game.

Returns:

  • (Array<PositionType>, nil)

    Array of position types for this game



82
# File 'lib/y_fantasy/resources/game.rb', line 82

option :position_types, optional: true, type: array_of(PositionType)

#roster_positionsArray<RosterPosition>? (readonly)

Returns Array of roster positions for this game.

Returns:

  • (Array<RosterPosition>, nil)

    Array of roster positions for this game



86
# File 'lib/y_fantasy/resources/game.rb', line 86

option :roster_positions, optional: true, type: array_of(RosterPosition)

#seasonInteger (readonly)

Returns The year of the season.

Returns:

  • (Integer)

    The year of the season



42
# File 'lib/y_fantasy/resources/game.rb', line 42

option :season, type: Types::Coercible::Integer

#stat_categoriesArray<StatCategory>? (readonly)

Returns Array of stat categories for this game.

Returns:

  • (Array<StatCategory>, nil)

    Array of stat categories for this game



90
# File 'lib/y_fantasy/resources/game.rb', line 90

option :stat_categories, optional: true, type: array_of(StatCategory)

#typeString (readonly)

Returns The type of game (eg. “full”).

Returns:

  • (String)

    The type of game (eg. “full”)



34
# File 'lib/y_fantasy/resources/game.rb', line 34

option :type

#urlString (readonly)

Returns The URL to the game’s home page.

Returns:

  • (String)

    The URL to the game’s home page



38
# File 'lib/y_fantasy/resources/game.rb', line 38

option :url

Class Method Details

.find_all_by_code(codes, with: [], **options) ⇒ Array<Game>

Finds all games by their code(s)

Examples:

Find all NFL games with game weeks

YFantasy::Game.find_all_by_code('nfl', with: :game_weeks)

Find all NFL and NBA games

YFantasy::Game.find_all_by_code(['nfl', 'nba'])

Parameters:

  • codes (String, Symbol, Array<String>, Array<Symbol>)

    The code(s) of the game(s) to find (e.g. ‘nfl’, ‘nba’)

  • with (Symbol, Array<Symbol>) (defaults to: [])

    Optional subresources to include

  • options (Hash)

    Additional options to pass to the API client

Returns:

  • (Array<Game>)

    Array of games matching the given code(s)



121
122
123
124
125
126
# File 'lib/y_fantasy/resources/game.rb', line 121

def self.find_all_by_code(codes, with: [], **options)
  subresources = Transformations::T.wrap_in_array(with)
  SubresourceValidator.validate!(self, subresources)
  data = YFantasy::Api::Client.get(:games, game_codes: codes, subresources: subresources, **options)
  Transformations::CollectionTransformer.new(:games).call(data)
end