Class: Basketball::Season::Game

Inherits:
ValueObject show all
Defined in:
lib/basketball/season/game.rb

Overview

Base class describing what all games have in common.

Direct Known Subclasses

Exhibition, Regular

Instance Method Summary collapse

Methods inherited from ValueObject

#<=>, #==, #[], #all_sorted_values, #hash, #to_h

Methods included from ValueObjectDSL

#all_sorted_value_keys, #all_value_keys, #value_keys, #value_reader

Constructor Details

#initialize(date:, home_opponent:, away_opponent:, opponent_type:) ⇒ Game

Returns a new instance of Game.

Raises:

  • (ArgumentError)


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

def initialize(date:, home_opponent:, away_opponent:, opponent_type:)
  super()

  raise ArgumentError, 'date is required'             unless date
  raise ArgumentError, 'home_opponent is required'    unless home_opponent
  raise ArgumentError, 'away_opponent is required'    unless away_opponent
  raise ArgumentError, 'teams cannot play themselves' if home_opponent == away_opponent
  raise ArgumentError, 'opponent_type is required'    unless opponent_type

  @date          = date
  @home_opponent = home_opponent
  @away_opponent = away_opponent
  @opponent_type = OpponentType.parse(opponent_type)

  freeze
end

Instance Method Details

#for?(team) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/basketball/season/game.rb', line 26

def for?(team)
  teams.include?(team)
end

#teamsObject



30
31
32
# File 'lib/basketball/season/game.rb', line 30

def teams
  [home_opponent, away_opponent]
end

#to_sObject



34
35
36
# File 'lib/basketball/season/game.rb', line 34

def to_s
  "#{date} - #{away_opponent} at #{home_opponent}"
end