class Livecal::RecurringEvents

Attributes

changes[R]
from[R]
source[R]
to[R]

Public Class Methods

call(...) click to toggle source
# File lib/livecal/recurring_events.rb, line 10
def self.call(...)
  new(...).to_a
end
new(source, from:, to:, changes:) click to toggle source
# File lib/livecal/recurring_events.rb, line 14
def initialize(source, from:, to:, changes:)
  @source = source
  @from = from
  @to = to
  @changes = changes.select do |change|
    change.uid == source.uid && change.sequence >= source.sequence
  end
end

Public Instance Methods

each(&block) click to toggle source
# File lib/livecal/recurring_events.rb, line 23
def each(&block)
  instances.each(&block)
end

Private Instance Methods

changed?(instance) click to toggle source
# File lib/livecal/recurring_events.rb, line 31
def changed?(instance)
  changes.any? { |change| change.recurrence_id == instance.dtstart }
end
duration() click to toggle source
# File lib/livecal/recurring_events.rb, line 35
def duration
  @duration ||= source.dtend - source.dtstart
end
instance_with_start(time) click to toggle source
# File lib/livecal/recurring_events.rb, line 39
def instance_with_start(time)
  source.dup.tap do |instance|
    instance.rrule = []
    instance.dtstart = time_in_zone(time)
    instance.dtend = time_in_zone(time + duration)
  end
end
instances() click to toggle source
# File lib/livecal/recurring_events.rb, line 47
def instances
  rrule
    .between(from, to)
    .collect { |start| instance_with_start(start) }
    .reject { |instance| changed?(instance) }
end
rrule() click to toggle source
# File lib/livecal/recurring_events.rb, line 54
def rrule
  RRule::Rule.new(
    source.rrule.first.value_ical,
    dtstart: source.dtstart,
    exdate: source.exdate,
    tzid: tzid
  )
end
time_in_zone(time) click to toggle source
# File lib/livecal/recurring_events.rb, line 63
def time_in_zone(time)
  ::Icalendar::Values::DateTime.new(time, "tzid" => tzid)
end
tzid() click to toggle source
# File lib/livecal/recurring_events.rb, line 67
def tzid
  @tzid ||= source.dtstart.time_zone.name
end