Wednesday, November 17, 2010

Using Math with Ruby Ranges

Back in August, I wrote a little Ruby library that extends math functions to ranges (https://github.com/Winslett/RubyRanges). The sole purpose of the library was to easily work with schedules and conflicts.

For instance, given I am available from 2 to 6, yet have scheduled events at 3 to 4 and 4:30 to 5:15, I could use simple math functions like the following:

  (2010-11-17 14:00:00..2010-11-17 18:00:00) - (2010-11-17 15:00:00..2010-11-17 16:00:00) - (2010-11-17 16:30:00..2010-11-17 17:15:00)

Should equal an array of ranges of times the person is available:

  [(2010-11-17 14:00:00..2010-11-17 15:00:00),(2010-11-17 16:00:00..2010-11-17 16:30:00),(2010-11-17 17:15:00..2010-11-17 18:00:00)]

Please take the library. I look to convert it into a Gem soon, but job comes first.

Chris

No comments: