Sha256: 83267b0bb883b2f7b82dca12bb62dafa8d0295686dcc1c3666ac77d02b665213
Contents?: true
Size: 1.3 KB
Versions: 15
Compression:
Stored size: 1.3 KB
Contents
# frozen_string_literal: true module Basketball module Season # Describes a result from the perspective of a team. class Detail < ValueObject value_reader :date, :home, :opponent_score, :opponent, :score alias home? home def initialize(date:, home:, opponent:, opponent_score:, score:) super() raise ArgumentError, 'date is required' unless date raise ArgumentError, 'opponent is required' unless opponent raise ArgumentError, 'score is required' unless score raise ArgumentError, 'opponent_score is required' unless opponent_score raise ArgumentError, 'home is required' if home.nil? raise CannotTieError, 'scores cannot be equal' if score == opponent_score @date = date @opponent = opponent @score = score @opponent_score = opponent_score @home = home freeze end def win? score > opponent_score end def loss? score < opponent_score end def to_s "[#{date}] #{win? ? 'Win' : 'Loss'} #{home? ? 'vs' : 'at'} #{opponent} (#{score}-#{opponent_score})" end end end end
Version data entries
15 entries across 15 versions & 1 rubygems