Models discrete and recurring events
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app/models
db
lib
spec
test
.gitignore
README.rdoc
init.rb

README.rdoc

Acts As Calendar

I haven't touched this in a dog's age, but angelic has taken the ball and run with it:

github.com/angelic/schedule_fu/tree/master

Anyone who found this interesting should work from her repository.

Old Readme

This rails plugin aims to provide support for calendar events, both discrete and recurring. The goal is to be able to attach a calendar to any model object, and to attach calendar events to any of that object's children or possibly descendents. The calendar data should be publishable in ical format, and possibly editable from as well, to the extent that the data model allows.

Events may occur on specific dates, recur monthly on a given day (the 15th), a given day of a given week (1st Thursday, Last Saturday), or a given weekday (Every Friday), or any combination of the above.

Recurring events are stored as patterns in the database, and are joined against a table of dates, decomposed into parts, into a view of event instances. This has the advantages of being easy and efficient to query, and of bypassing the typically non-standard database date functions. The disadvantage, of course, is that it requires a table of all potential dates against which to join. That being said, a century's worth of date data should only be a few hundred kilobytes, not large by today's standards. The limiting factor at the moment is in initially populating these data, it's fairly slow with ActiveRecord.

Status

The plugin is far from complete. Specifically it could use:

  1. A nice way of supplying a migration to the rails app

  2. A nice API for creating and querying events

  3. A suggested strategy for annotating events with metadata - names, categories, etc. I've purposedfully kept this out of the base models, figuring that folks would create, say, Course objects which would point to the CalendarEvent objects, but it's unclear if this is really workable.

  4. The icalendar output is incomplete

Getting Started

If you want to play with the object model anyway, install the plugin and:

  1. Copy the contents of db/migration.rb into a migration in the rails app, and migrate it.

  2. Create a calendar, e.g. calendar = Calendar.create_for_dates(Date.parse('2008-01-01'), Date.parse('2008-12-31'))

  3. Create an event, e.g. event = calendar.events.create_for('2008-01-01'). The create_for method accepts strings, dates, recurrence hashes, and enumerables of these. In the case of exactly two string or date arguments, the dates are taken to be endpoints of a range, otherwise they're taken to be specific occurrences of the event.

  4. Query for events:

calendar.events.find_by_date(Date.parse('2008-01-01'))

calendar.events.find_by_dates(Date.parse('2008-01-01'), Date.parse('2008-12-31'))

The good bit to figure out how would be how to combine date searches with searches for event metadata, e.g. categories. Probably some named scope stuff would work.