views:

262

answers:

1

I'm using Ruby on Rails to build a simple application to keep track of a shop's opening and closing times and its appointments, and I'm having some trouble validating the appointments against closings in the shop's schedule.

I've been using Runt to compose the schedule. For example, if the shop is open Monday morning from 9am-12pm closed for an hour for lunch and then open in the afternoon until 5pm, it would look like:

require 'runt'
include Runt

monday = DIWeek.new(Mon)
morning = REDay.new(9,00,12,00)
afternoon = REDAy.new(13,00,17,00)

expr = monday & morning & afternoon

For a given appointment (also a Runt Temporal Expression), how can I make sure that the appointment does overlap with the opening times and does not overlap the lunch hour (or other times before or after the opening times)?

I gather that Runt has an overlaps? method, but if I do something like:

expr.overlaps?(DIWeek.new(Mon) & REDay.new(10,00,11,00)) # the appointment is from 10-11am on Monday and should overlap the morning opening time

I get this error:

NoMethodError: undefined method `overlaps?' for #<Runt::Intersect:0x10483cc>

Can anyone please advises me on how to correct this error or else another way to solve this problem? Thanks very much for your help.

+1  A: 

The overlaps? method is defined only on Runt::Collection and Runt::DateRange. Perhaps you can create a DateRange object from your expr and then run overlap? on it.

sbwoodside
Thanks, sbwoodside. I think this will work.
trisignia