# Recurring Events feature set

**URL:** <https://www.ruby-forum.com/t/recurring-events-feature-set/140471>\
**Category:** Rails\
**Created:** [June 14, 2008, 4:27pm UTC](https://www.ruby-forum.com/t/recurring-events-feature-set/140471 "2008-06-14T16:27:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alan\_Wong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Alan\_Wong](https://www.ruby-forum.com/u/Alan_Wong)\
**Post date:** [June 14, 2008, 4:27pm UTC](https://www.ruby-forum.com/t/recurring-events-feature-set/140471/1 "2008-06-14T16:27:51Z")

</div>

Hi all,  
I’m a J2EE developer by day and I’m moonlighting to migrate my  
church’s website to a Rails application.

One of the fundamental abstractions that any organization needs to  
track is events. Events could be work schedules, pay cycles, meetings  
and so forth. Events recur, of course. I would like to brainstorm with  
you about possible solutions.

So on that note, I started to think about how to develop an events  
feature set for a Rails application. Some of constraints I have is  
that since this is fundamental to my organization’s process, we need  
to save Events with ActiveRecord into our database. (So I doubt Google  
Calendar would work but I could be convinced otherwise). Events at  
least have a title, description, start time and end time. But they  
also recur. Here’s where I get puzzled.

a) First solution: browse through the Outlook API (via MSDN) and  
reconstruct the classes that make up RecurrenceType and  
RecurrencePattern. RecurencePattern has child classes such as  
RecursMonthly, RecursDaily, and RecursMonthlyNth. It seems like the  
right kinds of abstraction for a helper class or a module. Perhaps it  
isn’t Rubyesque but refactoring can fix that problem.

The more important thing that bothers me about this set of classes is  
that it doesn’t seem appropriate to make them ActiveRecord classes.  
It’s just too busy with nouns, because subtypes of RecurrencePatterns  
are manifold. I personally might have to support a RecurrencePattern  
for every other Easter! Still an event has to be persisted with some  
sort of recurrence pattern.

b) Next solution: I’m wondering if it would be appropriate to use a  
RecurrencePattern hierarchy as a wrapper around the cron expression.  
Cron expressions would be persisted to the database. If an Event has a  
cron expression, we need to be able interpret the expression with  
intermediate classes so that a user can set the recurrence properties  
of the cron expression. The intermediate classes need to mediate in  
both directions between the UI (a la Outlook’s API) and the database  
(cron expression).

Like any lazy programmer, I thought there might be a plugin or gem  
available. A quick search this morning turns up inactive Ruby gems to  
do cron expressions. A search on plugins turns up little. Does anyone  
know if any resource that could be reused?

So I might have to do it myself. Writing the classes would take a lot  
of work but seems worthwhile. So worthwhile I wonder about mixing them  
in to Date or Time a la ActiveSupport. Has anyone attempted to do  
this?

Regards,  
Alan

---

<div class="post-metadata">

**Author:** ![Alan\_Wong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Alan\_Wong](https://www.ruby-forum.com/u/Alan_Wong)\
**Post date:** [June 14, 2008, 4:37pm UTC](https://www.ruby-forum.com/t/recurring-events-feature-set/140471/2 "2008-06-14T16:37:14Z")

</div>

On 14 Jun 2008, at 15:27, Alan Wong wrote:

> Hi all,  
> I’m a J2EE developer by day and I’m moonlighting to migrate my  
> church’s website to a Rails application.
> 
> One of the fundamental abstractions that any organization needs to  
> track is events. Events could be work schedules, pay cycles, meetings  
> and so forth. Events recur, of course. I would like to brainstorm with  
> you about possible solutions.

Does runt ([http://runt.rubyforge.org/](http://runt.rubyforge.org/)) look interesting ?

Fred

---

<div class="post-metadata">

**Author:** ![Alan\_Wong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Alan\_Wong](https://www.ruby-forum.com/u/Alan_Wong)\
**Post date:** [June 15, 2008, 2:46am UTC](https://www.ruby-forum.com/t/recurring-events-feature-set/140471/3 "2008-06-15T02:46:45Z")

</div>

Fred,  
I’ll probably try the Runt gem. It’s definitely an improvement over  
the .Net API  
because it provides a pattern language.

Here are my thoughts.

Though after browsing the RDoc, I noticed  
that neither Runt::TExpr nor Runt::Schedule provide a trivial way to  
persist their  
state to a database with the important constraint that one can  
reconstruct  
the object from the database. To be more specific about what I’m  
looking for,  
both of them have methods that will return an array of dates (not  
bad), but  
if one loads an array of dates (via ActiveRecord) from the database  
created  
by Runt::Schedule, one cannot reconstruct a Runt::Schedule or  
a ::TExpr  
object.

The reason that this may be a useful is that one might want to present  
the temporal expression in the UI using a set of forms (just as  
Outlook does).

Perhaps this is functionality that needs to be added to a gem that  
hasn’t reached 1.0  
state. I’m inclined to allow a ::Schedule to have a CronExpression  
object can  
returns a cron expression, which can be persisted as a string.  
CronExpression could  
parse a cron expression into a ::Schedule object.

Or perhaps, in the spirit of YAGNI, it ain’t bad for the client to  
always recreate  
a new schedule everytime they change a recurring event.

-Alan

On Jun 14, 10:36 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Alan\_Wong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Alan\_Wong](https://www.ruby-forum.com/u/Alan_Wong)\
**Post date:** [June 16, 2008, 4:04pm UTC](https://www.ruby-forum.com/t/recurring-events-feature-set/140471/4 "2008-06-16T16:04:17Z")

</div>

Andy -

On Jun 16, 8:10 am, AndyV [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> @Alan: For a similar situation I used an ARec model that was  
> composed\_with the TExpr/Schedule object.

Did you serialize?

Am confused by your “composed\_with” syntax - a plugin? I can’t find

I have solved this problem with serialization - but not the cleanest -  
nor the most efficient when processing large amounts of appointments.  
Have considered going towards an ical model to store them (erd is out  
there somewhere) - but not quick solution.

thanx - Jodi

---

<div class="post-metadata">

**Author:** ![Alan\_Wong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Alan\_Wong](https://www.ruby-forum.com/u/Alan_Wong)\
**Post date:** [June 16, 2008, 2:11pm UTC](https://www.ruby-forum.com/t/recurring-events-feature-set/140471/5 "2008-06-16T14:11:56Z")

</div>

@Alan: For a similar situation I used an ARec model that was  
composed\_with the TExpr/Schedule object.

---

<div class="post-metadata">

**Author:** ![Alan\_Wong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Alan\_Wong](https://www.ruby-forum.com/u/Alan_Wong)\
**Post date:** [June 16, 2008, 4:14pm UTC](https://www.ruby-forum.com/t/recurring-events-feature-set/140471/6 "2008-06-16T16:14:00Z")

</div>

On 16 Jun 2008, at 15:03, Jodi wrote:

> 

composed\_of:  
[http://api.rubyonrails.com/classes/ActiveRecord/Aggregations/ClassMethods.html](http://api.rubyonrails.com/classes/ActiveRecord/Aggregations/ClassMethods.html)

Fred

---

<div class="post-metadata">

**Author:** ![Alan\_Wong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Alan\_Wong](https://www.ruby-forum.com/u/Alan_Wong)\
**Post date:** [June 16, 2008, 6:09pm UTC](https://www.ruby-forum.com/t/recurring-events-feature-set/140471/7 "2008-06-16T18:09:44Z")

</div>

Sorry, not enough Starbucks this morning… 🙂

---

<div class="post-metadata">

**Author:** ![Alan\_Wong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Alan\_Wong](https://www.ruby-forum.com/u/Alan_Wong)\
**Post date:** [June 16, 2008, 4:38pm UTC](https://www.ruby-forum.com/t/recurring-events-feature-set/140471/8 "2008-06-16T16:38:11Z")

</div>

Frederick -

On 16-Jun-08, at 10:13 AM, Frederick C. wrote:

> > Have considered going towards an ical model to store them (erd is out  
> > there somewhere) - but not quick solution.
> > 
> > thanx - Jodi
> > 
> > >

Thank you Frederic - never used that bit of magic. Nice sugar for this  
problem - not as sweet as a native data storage but better than my  
present mess.

Jodi

---

<div class="post-metadata">

**Author:** ![Alan\_Wong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Alan\_Wong](https://www.ruby-forum.com/u/Alan_Wong)\
**Post date:** [June 16, 2008, 10:27pm UTC](https://www.ruby-forum.com/t/recurring-events-feature-set/140471/9 "2008-06-16T22:27:33Z")

</div>

Would you mind sharing your composed\_with solution? It sounds very  
interesting.

Thanks
