Class: SuperSpreader::PeakSchedule

Inherits:
Object
  • Object
show all
Defined in:
lib/super_spreader/peak_schedule.rb

Instance Method Summary collapse

Constructor Details

#initialize(on_peak_wday_range:, on_peak_hour_range:, timezone:) ⇒ PeakSchedule

Returns a new instance of PeakSchedule.



7
8
9
10
11
# File 'lib/super_spreader/peak_schedule.rb', line 7

def initialize(on_peak_wday_range:, on_peak_hour_range:, timezone:)
  @on_peak_wday_range = on_peak_wday_range
  @on_peak_hour_range = on_peak_hour_range
  @timezone = timezone
end

Instance Method Details

#on_peak?(time = Time.current) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
# File 'lib/super_spreader/peak_schedule.rb', line 13

def on_peak?(time = Time.current)
  time_in_zone = time.in_time_zone(@timezone)

  is_on_peak_day = @on_peak_wday_range.cover?(time_in_zone.wday)
  is_on_peak_hour = @on_peak_hour_range.cover?(time_in_zone.hour)

  is_on_peak_day && is_on_peak_hour
end