Class: Availability::CalendarParser

Inherits:
Object
  • Object
show all
Defined in:
lib/availability/calendar_parser.rb

Overview

Parses ICS events and expands occurrences into privacy-safe busy periods.

Constant Summary collapse

MAX_EVENTS_PER_CALENDAR =
10_000
NULL_LOGGER =
Logger.new(IO::NULL)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timezone:) ⇒ CalendarParser

Returns a new instance of CalendarParser.



20
21
22
23
# File 'lib/availability/calendar_parser.rb', line 20

def initialize(timezone:)
  @timezone = timezone
  @ignored_event_count = 0
end

Instance Attribute Details

#ignored_event_countObject (readonly)

Returns the value of attribute ignored_event_count.



18
19
20
# File 'lib/availability/calendar_parser.rb', line 18

def ignored_event_count
  @ignored_event_count
end

Instance Method Details

#parse(ics, range_start:, range_end:, label: 'Calendar') ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/availability/calendar_parser.rb', line 25

def parse(ics, range_start:, range_end:, label: 'Calendar')
  reset_diagnostics
  with_silenced_dependency_logging { parse_periods(ics, range_start, range_end, label) }
rescue RecurrenceExpander::LimitError
  raise ParseError, "#{label} exceeded the safe recurrence expansion limit"
rescue ParseError
  raise
rescue StandardError => e
  raise ParseError, "#{label} could not be parsed (#{e.class})"
end