Class: TaskJuggler::ICalendar::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/taskjuggler/ICalendar.rb

Overview

Base class for all ICalendar components.

Direct Known Subclasses

Event, Journal, Todo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ical, uid, summary, startDate) ⇒ Component

Returns a new instance of Component.



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/taskjuggler/ICalendar.rb', line 37

def initialize(ical, uid, summary, startDate)
  @ical = ical
  @type = self.class.to_s.split('::').last.upcase
  @uid = uid + "-#{@type}"
  @summary = summary
  @startDate = startDate

  # Optional attributes
  @description = nil
  @relatedTo = nil
  @organizer = nil
  @attendees = []
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



34
35
36
# File 'lib/taskjuggler/ICalendar.rb', line 34

def description
  @description
end

#organizerObject

Returns the value of attribute organizer.



34
35
36
# File 'lib/taskjuggler/ICalendar.rb', line 34

def organizer
  @organizer
end

#relatedToObject

Returns the value of attribute relatedTo.



34
35
36
# File 'lib/taskjuggler/ICalendar.rb', line 34

def relatedTo
  @relatedTo
end

#uidObject (readonly)

Returns the value of attribute uid.



35
36
37
# File 'lib/taskjuggler/ICalendar.rb', line 35

def uid
  @uid
end

Instance Method Details

#addAttendee(name, email) ⇒ Object



55
56
57
# File 'lib/taskjuggler/ICalendar.rb', line 55

def addAttendee(name, email)
  @attendees << Person.new(name, email)
end

#setOrganizer(name, email) ⇒ Object



51
52
53
# File 'lib/taskjuggler/ICalendar.rb', line 51

def setOrganizer(name, email)
  @organizer = Person.new(name, email)
end

#to_sObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/taskjuggler/ICalendar.rb', line 59

def to_s
  str = <<"EOT"
BEGIN:V#{@type}
DTSTAMP:#{dateTime(TjTime.new.utc)}
CREATED:#{dateTime(@ical.creationDate)}
UID:#{@uid}
LAST-MODIFIED:#{dateTime(@ical.lastModified)}
SUMMARY:#{quoted(@summary)}
DTSTART:#{dateTime(@startDate)}
EOT
  str += "DESCRIPTION:#{quoted(@description)}\n" if @description
  str += "RELATED-TO:#{@relatedTo}\n" if @relatedTo

  if @organizer
    str += "ORGANIZER;CN=#{@organizer.name}:mailto:#{@organizer.email}\n"
  end
  @attendees.each do |attendee|
    str += "ATTENDEE;CN=#{attendee.name}:mailto:#{attendee.email}\n"
  end

  str += yield if block_given?

  str += "END:V#{@type}\n\n"
end