Class: Basketball::Season::Result

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(game:, home_score:, away_score:) ⇒ Result

Returns a new instance of Result.

Raises:

  • (ArgumentError)


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_scoreObject (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

#gameObject (readonly)

Returns the value of attribute game.



12
13
14
# File 'lib/basketball/season/result.rb', line 12

def game
  @game
end

#home_scoreObject (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_sObject



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