iCalendar – Internet calendaring, Ruby style
This is a Ruby library for dealing with iCalendar files. Rather than explaining myself, here is the introduction from RFC-2445, which defines the format:
The use of calendaring and scheduling has grown considerably in the last decade. Enterprise and inter-enterprise business has become dependent on rapid scheduling of events and actions using this information technology. However, the longer term growth of calendaring and scheduling, is currently limited by the lack of Internet standards for the message content types that are central to these knowledgeware applications. This memo is intended to progress the level of interoperability possible between dissimilar calendaring and scheduling applications. This memo defines a MIME content type for exchanging electronic calendaring and scheduling information. The Internet Calendaring and Scheduling Core Object Specification, or iCalendar, allows for the capture and exchange of information normally stored within a calendaring and scheduling application; such as a Personal Information Manager (PIM) or a Group Scheduling product.
The iCalendar format is suitable as an exchange format between applications or systems. The format is defined in terms of a MIME content type. This will enable the object to be exchanged using several transports, including but not limited to SMTP, HTTP, a file system, desktop interactive protocols such as the use of a memory- based clipboard or drag/drop interactions, point-to-point asynchronous communication, wired-network transport, or some form of unwired transport such as infrared might also be used.
Now for some examples:
-
Creating iCalendars.
# Create a calendar with a single event (Method 1) cal = Icalendar::Calendar.new event = Icalendar::Event.new # Set some properties for this event event.user_id = "[email protected]" event. = DateTime.now event.start = Date.new(2005, 04, 29) event.end = Date.new(2005, 04, 28) event.summary = "Meeting with the man." event.klass = "PRIVATE" # Now add it to the calendar cal.add event # Create a calendar with a single event (Method 2) cal2 = Icalendar::Calendar.new event = cal.event # This automatically adds the event to the calendar event.user_id = "[email protected]" event. = DateTime.now # Create a calendar with a single event (Method 3) cal3 = Icalendar::Calendar.new cal3.event do user_id "[email protected]" DateTime.now end # We can output the calendars as strings to write to a file, # network port, database etc. cal_string = cal.to_ical puts cal_string
Parsing iCalendars:
require 'icalendar'
require 'date'
# Open a file or string to parse
cal_file = File.open("single_event.ics")
# Parser returns an array of calendars because a single file
# can have multiple calendar objects.
cals = Icalendar::Parser.new(cal_file).parse
cal = cals.first
# Now you can access the cal object in just the same way I created it
event = cal.events.first
puts "user_id: " + event.user_id
puts "summary: " + event.summary
Including the iCalendar library when using RubyGem:
begin
require 'rubygems'
require_gem 'icalendar', ">= 0.96"
rescue LoadError
require 'icalendar'
end
Download
The latest release version of this library can be found at
If you would like to help with development or use the most current version you can check out the tree from the subversion repository:
-
svn co rosejn.net/svn/icalendar icalendar
Documentation can be found at
Installation
This library uses rubygems for distribution and installation:
$ gem install icalendar
License
This library is released under the same license as Ruby itself.
Support & Contributions
The iCalendar library homepage is icalendar.rubyforge.org/
There is an [email protected] mailing list that can be used for asking questions, making comments or submitting patches.