Class: Basketball::Season::Matchup

Inherits:
Object
  • Object
show all
Defined in:
lib/basketball/season/matchup.rb

Overview

A Matchup is a late materialization of a game. While a game is a skeleton for a future matchup, it does not materialize until game time (rosters could change right up until game time).

Defined Under Namespace

Classes: PlayersOnBothTeamsError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(game:, home_players: [], away_players: []) ⇒ Matchup

Returns a new instance of Matchup.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/basketball/season/matchup.rb', line 12

def initialize(game:, home_players: [], away_players: [])
  raise ArgumentError, 'game is required' unless game

  @game         = game
  @home_players = home_players.uniq
  @away_players = away_players.uniq

  if home_players.intersect?(away_players)
    raise PlayersOnBothTeamsError, 'players cannot be on both home and away team'
  end

  freeze
end

Instance Attribute Details

#away_playersObject (readonly)

Returns the value of attribute away_players.



10
11
12
# File 'lib/basketball/season/matchup.rb', line 10

def away_players
  @away_players
end

#gameObject (readonly)

Returns the value of attribute game.



10
11
12
# File 'lib/basketball/season/matchup.rb', line 10

def game
  @game
end

#home_playersObject (readonly)

Returns the value of attribute home_players.



10
11
12
# File 'lib/basketball/season/matchup.rb', line 10

def home_players
  @home_players
end