Class: IcalImporter::Collector

Inherits:
Object
  • Object
show all
Defined in:
lib/ical_importer/collector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(events) ⇒ Collector

Returns a new instance of Collector.



5
6
7
8
9
# File 'lib/ical_importer/collector.rb', line 5

def initialize(events)
  @events = events
  @single_events = []
  @recurrence_events = []
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



3
4
5
# File 'lib/ical_importer/collector.rb', line 3

def events
  @events
end

#recurrence_eventsObject (readonly)

Returns the value of attribute recurrence_events.



3
4
5
# File 'lib/ical_importer/collector.rb', line 3

def recurrence_events
  @recurrence_events
end

#single_eventsObject (readonly)

Returns the value of attribute single_events.



3
4
5
# File 'lib/ical_importer/collector.rb', line 3

def single_events
  @single_events
end

Instance Method Details

#collectObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ical_importer/collector.rb', line 11

def collect
  self.tap do
    recurrence_builder = RecurrenceEventBuilder.new
    single_events.tap do |c|
      events.each do |remote_event|
        c << Builder.new(remote_event, recurrence_builder).build
      end
      @recurrence_events = recurrence_builder.build.built_events.flatten.compact
      c.flatten!
      c.compact!
    end
  end
end