Class: Vpim::Icalendar::Vevent

Inherits:
Object
  • Object
show all
Includes:
Property::Base, Property::Common, Property::Location, Property::Priority, Property::Recurrence, Property::Resources
Defined in:
lib/vpim/vevent.rb

Defined Under Namespace

Classes: Maker

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Property::Recurrence

#occurences, #occurs_in?, #rdates

Methods included from Property::Resources

#resources

Methods included from Property::Location

#geo, #location

Methods included from Property::Priority

#priority

Methods included from Property::Common

#access_class, #attachments, #attendee?, #attendees, #categories, #comments, #contacts, #created, #description, #dtstamp, #dtstart, #lastmod, #organizer, #sequence, #status, #summary, #uid, #url

Methods included from Property::Base

#propinteger, #proptext, #proptextarray, #proptextlistarray, #proptime, #proptoken, #propvalue, #propvaluearray

Constructor Details

#initialize(fields) ⇒ Vevent

:nodoc:



31
32
33
34
35
36
37
38
39
# File 'lib/vpim/vevent.rb', line 31

def initialize(fields) #:nodoc:
  outer, inner = Vpim.outer_inner(fields)

  @properties = Vpim::DirectoryInfo.create(outer)

  @elements = inner

  # See "TODO - fields" in dirinfo.rb
end

Class Method Details

.create(start = Time.now, fields = []) ⇒ Object

Create a new Vevent object. All events must have a DTSTART field, specify it as either a Time or a Date in start, it defaults to “now” (is this useful?).

If specified, fields must be either an array of Field objects to add, or a Hash of String names to values that will be used to build Field objects. The latter is a convenient short-cut allowing the Field objects to be created for you when called like:

Vevent.create(Date.today, 'SUMMARY' => "today's event")

TODO - maybe events are usually created in a particular way? With a start/duration or a start/end? Maybe I can make it easier. Ideally, I would like to make it hard to encode an invalid Event.



68
69
70
71
72
73
74
75
# File 'lib/vpim/vevent.rb', line 68

def Vevent.create(start = Time.now, fields=[])
  dtstart = DirectoryInfo::Field.create('DTSTART', start)
  di = DirectoryInfo.create([ dtstart ], 'VEVENT')

  Vpim::DirectoryInfo::Field.create_array(fields).each { |f| di.push_unique f }

  new(di.to_a)
end

.create_yearly(date, summary) ⇒ Object

Creates a yearly repeating event, such as for a birthday.



78
79
80
81
82
83
84
# File 'lib/vpim/vevent.rb', line 78

def Vevent.create_yearly(date, summary)
  create(
    date,
    'SUMMARY' => summary.to_str,
    'RRULE' => 'FREQ=YEARLY'
    )
end

Instance Method Details

#accept(invitee) ⇒ Object

Accept an event invitation. The invitee is the Address that wishes to accept the event invitation as confirmed.

The event created is identical to this one, but

  • without the attendees

  • with the invitee added with a PARTSTAT of ACCEPTED



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/vpim/vevent.rb', line 92

def accept(invitee)
  # FIXME - move to Vpim::Itip.
  invitee = invitee.copy
  invitee.partstat = 'ACCEPTED'

  fields = []

  @properties.each_with_index do
    |f,i|

    # put invitee in as field[1]
    fields << invitee.encode('ATTENDEE') if i == 1
    
    fields << f unless f.name? 'ATTENDEE'
  end

  Vevent.new(fields)
end

#dtendObject

The end time for this calendar component. For an Event, if there is no end time, then nil is returned, and the event takes up no time. However, the end time will be calculated from the event duration, if present.



140
141
142
143
144
145
146
147
148
149
# File 'lib/vpim/vevent.rb', line 140

def dtend
  dte = @properties.field 'DTEND'
  if dte
    dte.to_time.first
  elsif duration
      dtstart + duration
  else
    nil
  end
end

#durationObject

The duration in seconds of a Event, Todo, or Vfreebusy component, or for Alarms, the delay period prior to repeating the alarm. The duration is calculated from the DTEND and DTBEGIN fields if the DURATION field is not present. Durations of zero seconds are possible.



121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/vpim/vevent.rb', line 121

def duration
  dur = @properties.field 'DURATION'
  dte = @properties.field 'DTEND'
  if !dur
    return nil unless dte

    b = dtstart
    e = dtend

    return (e - b).to_i
  end

  Icalendar.decode_duration(dur.value_raw)
end

#fieldsObject

TODO - derive everything from Icalendar::Component to get this kind of stuff?



42
43
44
45
46
47
# File 'lib/vpim/vevent.rb', line 42

def fields #:nodoc:
  f = @properties.to_a
  last = f.pop
  f.push @elements
  f.push last
end

#propertiesObject

:nodoc:



49
50
51
# File 'lib/vpim/vevent.rb', line 49

def properties #:nodoc:
  @properties
end

#transparencyObject

In iTIP, whether this event is OPAQUE or TRANSPARENT to scheduling. If transparency is not explicitly set, it defaults to OPAQUE.



113
114
115
# File 'lib/vpim/vevent.rb', line 113

def transparency
  proptoken 'TRANSP', ["OPAQUE", "TRANSPARENT"], "OPAQUE"
end