Method: Vpim::Icalendar::Vevent.create
- Defined in:
- lib/vpim/vevent.rb
.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 |