class Livecal::Parser

Attributes

calendar_source[R]
from[R]
to[R]

Public Class Methods

call(...) click to toggle source
# File lib/livecal/parser.rb, line 9
def self.call(...)
  new(...).call
end
new(calendar_source, from:, to:) click to toggle source
# File lib/livecal/parser.rb, line 13
def initialize(calendar_source, from:, to:)
  @calendar_source = calendar_source
  @from = from
  @to = to
end

Public Instance Methods

call() click to toggle source
# File lib/livecal/parser.rb, line 19
def call
  Calendar.new(events.collect { |event| Event.from_ical(event) })
end

Private Instance Methods

events() click to toggle source
# File lib/livecal/parser.rb, line 27
def events
  (
    standalone_events + recurring_events + recurring_changes
  ).sort_by(&:dtstart)
end
instances(event) click to toggle source
# File lib/livecal/parser.rb, line 44
def instances(event)
  RecurringEvents.call(
    event,
    from: from,
    to: to,
    changes: calendar_source.recurring_changes
  )
end
recurring_changes() click to toggle source
# File lib/livecal/parser.rb, line 33
def recurring_changes
  within_window(calendar_source.recurring_changes)
end
recurring_events() click to toggle source
# File lib/livecal/parser.rb, line 37
def recurring_events
  calendar_source
    .recurring_events
    .collect { |event| instances(event) }
    .flatten
end
standalone_events() click to toggle source
# File lib/livecal/parser.rb, line 53
def standalone_events
  within_window(calendar_source.standalone_events)
end
within_window(events) click to toggle source
# File lib/livecal/parser.rb, line 57
def within_window(events)
  events.select { |event| event.dtstart >= from && event.dtstart <= to }
end