Class: Almanack::EventSource::Ical

Inherits:
Object
  • Object
show all
Defined in:
lib/almanack/event_source/ical.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Ical

Returns a new instance of Ical.



6
7
8
# File 'lib/almanack/event_source/ical.rb', line 6

def initialize(io)
  @io = io
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



4
5
6
# File 'lib/almanack/event_source/ical.rb', line 4

def io
  @io
end

Class Method Details

.from(*args) ⇒ Object



32
33
34
# File 'lib/almanack/event_source/ical.rb', line 32

def self.from(*args)
  self.new(*args)
end

Instance Method Details

#events_between(date_range) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/almanack/event_source/ical.rb', line 10

def events_between(date_range)
  return enum_for(__method__, date_range).to_a unless block_given?

  from, to = [date_range.min, date_range.max]

  each_ical_event do |ical_event|
    if ical_event.rrule.empty?
      if from < ical_event.dtend
        yield event_from(ical_event)
      end
    else
      ical_event.occurrences_between(from, to).each do |occurrence|
        yield event_from(ical_event, occurrence: occurrence)
      end
    end
  end
end

#serialized_between(date_range) ⇒ Object



28
29
30
# File 'lib/almanack/event_source/ical.rb', line 28

def serialized_between(date_range)
  { events: events_between(date_range).map(&:serialized) }
end