Class: SportsManager::TournamentDay

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/sports_manager/tournament_day.rb,
lib/sports_manager/tournament_day/validator.rb

Overview

Public: One of the tournament’s day with their specific date, duration, and timeslots available

Defined Under Namespace

Classes: Validator

Constant Summary collapse

MAX_HOUR =
24
ONE_HOUR =
60

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date:, start_hour:, end_hour:) ⇒ TournamentDay

Returns a new instance of TournamentDay.



19
20
21
22
23
24
# File 'lib/sports_manager/tournament_day.rb', line 19

def initialize(date:, start_hour:, end_hour:)
  @date = date.to_s
  @start_hour = start_hour.to_i
  @end_hour = end_hour.to_i
  Validator.new(self).validate!
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



13
14
15
# File 'lib/sports_manager/tournament_day.rb', line 13

def date
  @date
end

#end_hourObject (readonly)

Returns the value of attribute end_hour.



13
14
15
# File 'lib/sports_manager/tournament_day.rb', line 13

def end_hour
  @end_hour
end

#start_hourObject (readonly)

Returns the value of attribute start_hour.



13
14
15
# File 'lib/sports_manager/tournament_day.rb', line 13

def start_hour
  @start_hour
end

Class Method Details

.for(date:, start_hour:, end_hour:) ⇒ Object



15
16
17
# File 'lib/sports_manager/tournament_day.rb', line 15

def self.for(date:, start_hour:, end_hour:)
  new(date: date, start_hour: start_hour, end_hour: end_hour)
end

Instance Method Details

#<=>(other) ⇒ Object



34
35
36
37
38
# File 'lib/sports_manager/tournament_day.rb', line 34

def <=>(other)
  return unless instance_of?(other.class)

  equality(other).find(-> { 0 }, &:nonzero?)
end

#timeslots(interval: ONE_HOUR) ⇒ Object



26
27
28
# File 'lib/sports_manager/tournament_day.rb', line 26

def timeslots(interval: ONE_HOUR)
  TimeslotBuilder.build(tournament_day: self, interval: interval)
end

#total_timeObject



30
31
32
# File 'lib/sports_manager/tournament_day.rb', line 30

def total_time
  @total_time ||= end_hour - start_hour if start_hour <= end_hour
end