Class: Basketball::Season::Result
- Inherits:
-
Object
- Object
- Basketball::Season::Result
- Extended by:
- Forwardable
- Defined in:
- lib/basketball/season/result.rb
Overview
Base class describing the end result of a game. This should/could be sub-classed to include more sport-specific information.
Defined Under Namespace
Classes: CannotTieError
Instance Attribute Summary collapse
-
#away_score ⇒ Object
readonly
Returns the value of attribute away_score.
-
#game ⇒ Object
readonly
Returns the value of attribute game.
-
#home_score ⇒ Object
readonly
Returns the value of attribute home_score.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#initialize(game:, home_score:, away_score:) ⇒ Result
constructor
A new instance of Result.
- #to_s ⇒ Object
Constructor Details
#initialize(game:, home_score:, away_score:) ⇒ Result
Returns a new instance of Result.
16 17 18 19 20 21 22 23 |
# File 'lib/basketball/season/result.rb', line 16 def initialize(game:, home_score:, away_score:) raise ArgumentError, 'game is required' unless game raise CannotTieError, "#{game} ended in a tie" if home_score == away_score @game = game @home_score = home_score.to_i @away_score = away_score.to_i end |
Instance Attribute Details
#away_score ⇒ Object (readonly)
Returns the value of attribute away_score.
12 13 14 |
# File 'lib/basketball/season/result.rb', line 12 def away_score @away_score end |
#game ⇒ Object (readonly)
Returns the value of attribute game.
12 13 14 |
# File 'lib/basketball/season/result.rb', line 12 def game @game end |
#home_score ⇒ Object (readonly)
Returns the value of attribute home_score.
12 13 14 |
# File 'lib/basketball/season/result.rb', line 12 def home_score @home_score end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
29 30 31 32 33 |
# File 'lib/basketball/season/result.rb', line 29 def ==(other) game == other.game && home_score == other.home_score && away_score == other.away_score end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/basketball/season/result.rb', line 25 def to_s "#{game.date} - #{away_opponent} (#{away_score}) at #{home_opponent} (#{home_score})" end |