Class: Availability::RecurrenceExpander
- Inherits:
-
Object
- Object
- Availability::RecurrenceExpander
- Defined in:
- lib/availability/recurrence_expander.rb
Overview
Expands recurrences in bounded chunks and enforces occurrence-count limits.
Defined Under Namespace
Classes: LimitError
Constant Summary collapse
- MAX_OCCURRENCES_PER_EVENT =
10_000- MAX_OCCURRENCES_PER_CALENDAR =
50_000- SECONDLY_CHUNK_SECONDS =
60 * 60
- MINUTELY_CHUNK_SECONDS =
24 * 60 * 60
Instance Method Summary collapse
- #expand(event, range_start:, range_end:) ⇒ Object
-
#initialize ⇒ RecurrenceExpander
constructor
A new instance of RecurrenceExpander.
Constructor Details
#initialize ⇒ RecurrenceExpander
Returns a new instance of RecurrenceExpander.
13 14 15 |
# File 'lib/availability/recurrence_expander.rb', line 13 def initialize @calendar_occurrence_count = 0 end |
Instance Method Details
#expand(event, range_start:, range_end:) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/availability/recurrence_expander.rb', line 17 def (event, range_start:, range_end:) occurrences = {} cursor = range_start chunk_seconds = expansion_chunk_seconds(event, range_start, range_end) while cursor < range_end chunk_end = [cursor + chunk_seconds, range_end].min add_occurrences(occurrences, event, cursor, chunk_end) cursor = chunk_end end occurrences.values end |