Class: Markdo::IcsExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/markdo/ics_exporter.rb

Defined Under Namespace

Classes: Event

Instance Method Summary collapse

Constructor Details

#initialize(task_collection) ⇒ IcsExporter

Returns a new instance of IcsExporter.



5
6
7
# File 'lib/markdo/ics_exporter.rb', line 5

def initialize(task_collection)
  @task_collection = task_collection
end

Instance Method Details

#to_icsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/markdo/ics_exporter.rb', line 9

def to_ics
  buf = []

  buf << 'BEGIN:VCALENDAR'
  buf << 'VERSION:2.0'
  buf << 'CALSCALE:GREGORIAN'
  buf << 'METHOD:PUBLISH'
  buf << 'X-WR-CALNAME:Markdo Due Dates'
  buf << events.map { |event| event.to_ics }
  buf << 'END:VCALENDAR'

  buf.
    flatten.
    map { |line| "#{line}\n" }.
    join
end