title: Working with multiple time ranges in Rails
body: <p>An appointment system: many <b>rooms</b> have <b>bookings</b> during a specific day, and I need to build code that suggests <b>three 30-minute free times</b> to any user across those rooms.</p>
  
  <p>Each <code>booking</code> has a <code>start_time</code> and <code>end_time</code>.</p>
  
  <p>So, between the hours of 8am and 6pm on this one day, I need to collect all the <code>bookings</code>, isolate the times between those bookings' ranges, then choose three of those free times at random. Something like...</p>
  
  <pre><code>@bookings = Booking.where("room_id IN (?)", @rooms.collect(&amp;:id))
  @busy_times = @bookings.collect{|b| b.start_time..b.end_time}
  @empty_times = (@day.end_time - @day.start_time) - @busy_times # so to speak
  </code></pre>
  
  <p>In general, I can do the coding necessary for this sort of problem, but I don't really know how to work effectively with multiple time ranges.</p>