Class: Basketball::Season::Game
- Inherits:
-
ValueObject
- Object
- ValueObject
- Basketball::Season::Game
- Defined in:
- lib/basketball/season/game.rb
Overview
Base class describing what all games have in common.
Direct Known Subclasses
Instance Method Summary collapse
- #for?(team) ⇒ Boolean
-
#initialize(date:, home_opponent:, away_opponent:, opponent_type:) ⇒ Game
constructor
A new instance of Game.
- #teams ⇒ Object
- #to_s ⇒ Object
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.
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
26 27 28 |
# File 'lib/basketball/season/game.rb', line 26 def for?(team) teams.include?(team) end |
#teams ⇒ Object
30 31 32 |
# File 'lib/basketball/season/game.rb', line 30 def teams [home_opponent, away_opponent] end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/basketball/season/game.rb', line 34 def to_s "#{date} - #{away_opponent} at #{home_opponent}" end |