Class: Rem2ics::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/rem2ics/converter.rb

Overview

Reminder files in, one iCalendar out.

The conversion is a fold over what Remind gives: every reminder in every file becomes an event, in file order, in one VCALENDAR. What it skips is what a calendar has nowhere to put -- RUN reminders execute shell commands, CAL and PS reminders draw on a PostScript calendar, and none of them is an appointment.

"Today" is pinned for the whole conversion, because it is what a relative trigger is relative to: REM Mon starts on a different Monday depending on when it is asked. Pinning it makes the same file convert to the same calendar every time, which is what makes the output diffable and the conversion testable.

Constant Summary collapse

PRODID =
"-//rem2ics//NONSGML rem2ics #{VERSION}//EN"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session: Remind::Session.new, horizon: Recurrence::DEFAULT_HORIZON, organizer: nil, warnings: $stderr) ⇒ Converter

Returns a new instance of Converter.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rem2ics/converter.rb', line 30

def initialize(
  session: Remind::Session.new,
  horizon: Recurrence::DEFAULT_HORIZON,
  organizer: nil,
  warnings: $stderr
)
  @session = session
  @horizon = horizon
  @organizer = organizer || self.class.local_address
  @warnings = warnings
end

Instance Attribute Details

#horizonObject (readonly)

Returns the value of attribute horizon.



28
29
30
# File 'lib/rem2ics/converter.rb', line 28

def horizon
  @horizon
end

#organizerObject (readonly)

Returns the value of attribute organizer.



28
29
30
# File 'lib/rem2ics/converter.rb', line 28

def organizer
  @organizer
end

#sessionObject (readonly)

Returns the value of attribute session.



28
29
30
# File 'lib/rem2ics/converter.rb', line 28

def session
  @session
end

#warningsObject (readonly)

Returns the value of attribute warnings.



28
29
30
# File 'lib/rem2ics/converter.rb', line 28

def warnings
  @warnings
end

Class Method Details

.local_addressObject

id -nu@uname -n, which is what the Perl this descends from used, and is as good a guess at an organizer as a reminder file can support.



44
45
46
47
48
# File 'lib/rem2ics/converter.rb', line 44

def self.local_address
   = Etc.getlogin || ENV.fetch("USER", "remind")

  "#{}@#{Etc.uname.fetch(:nodename)}"
end

Instance Method Details

#call(paths, today: Date.today) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/rem2ics/converter.rb', line 50

def call(paths, today: Date.today)
  session.today = today

  calendar.tap do |ical|
    paths.each { |path| add_file(ical, path) }
  end
end