class TaskJuggler::ICalendar

This class implements a very basic RFC5545 compliant iCalendar file generator. It currently only supports a very small subset of the tags that are needed for TaskJuggler.

Constants

LINELENGTH

The maximum allowed length of a content line without line end character.

Attributes

creationDate[RW]
lastModified[RW]
uid[R]

Public Class Methods

new(uid) click to toggle source
# File lib/taskjuggler/ICalendar.rb, line 177
def initialize(uid)
  @uid = "#{AppConfig.packageName}-#{uid}"
  @creationDate = @lastModified = TjTime.new.utc

  @todos = []
  @events = []
  @journals = []
end

Public Instance Methods

addEvent(event) click to toggle source

Add a new VEVENT component. For internal use only!

# File lib/taskjuggler/ICalendar.rb, line 192
def addEvent(event)
  @events << event
end
addJournal(journal) click to toggle source

Add a new VJOURNAL component. For internal user only!

# File lib/taskjuggler/ICalendar.rb, line 197
def addJournal(journal)
  @journals << journal
end
addTodo(todo) click to toggle source

Add a new VTODO component. For internal use only!

# File lib/taskjuggler/ICalendar.rb, line 187
def addTodo(todo)
  @todos << todo
end
dateTime(date) click to toggle source
# File lib/taskjuggler/ICalendar.rb, line 219
def dateTime(date)
  date.to_s("%Y%m%dT%H%M%SZ", 'UTC')
end
to_s() click to toggle source
# File lib/taskjuggler/ICalendar.rb, line 201
    def to_s
      str = <<"EOT"
BEGIN:VCALENDAR
PRODID:-//The #{AppConfig.softwareName} Project/NONSGML #{AppConfig.softwareName} #{AppConfig.version}//EN
VERSION:2.0

EOT
      @todos.each { |todo| str += todo.to_s }
      @events.each { |event| str += event.to_s }
      @journals.each { |journal| str += journal.to_s }

      str << <<"EOT"
END:VCALENDAR
EOT

      foldLines(str)
    end

Private Instance Methods

foldLines(str) click to toggle source

Make sure that no line is longer than LINELENTH octets (excl. the newline character)

# File lib/taskjuggler/ICalendar.rb, line 227
def foldLines(str)
  newStr = ''
  str.each_line do |line|
    bytes = 0
    line.each_utf8_char do |c|
      # Make sure we support Ruby 1.8 and 1.9 String handling.
      cBytes = c.bytesize
      if bytes + cBytes > LINELENGTH && c != "\n"
        newStr += "\n "
        bytes = 0
      else
        bytes += cBytes
      end
      newStr << c
    end
  end
  # Convert line ends to CR+LF
  newStr.gsub(/\n/, "\r\n")
end