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

#occurrences, #occurs_in?, #rdates, #rrule

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

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

Constructor Details

#initialize(fields) ⇒ Vevent

:nodoc:



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

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”

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")


64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/vpim/vevent.rb', line 64

def Vevent.create(start = Time.now, fields=[])
  # 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.
  # - I don't think its useful to have a default dtstart for events
  # - also, I don't think dstart is mandatory
  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.



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

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



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

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 Event. If the DTEND field is not present, but the DURATION field is, the end will be calculated from DTSTART and DURATION.



130
131
132
# File 'lib/vpim/vevent.rb', line 130

def dtend
  propend 'DTEND'
end

#durationObject

The duration in seconds of an Event, or nil if unspecified. If the DURATION field is not present, but the DTEND field is, the duration is calculated from DTSTART and DTEND. Durations of zero seconds are possible.



123
124
125
# File 'lib/vpim/vevent.rb', line 123

def duration
  propduration 'DTEND'
end

#fieldsObject

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



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

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

#propertiesObject

:nodoc:



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

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.



115
116
117
# File 'lib/vpim/vevent.rb', line 115

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