Skip to content

Instantly share code, notes, and snippets.

@arbales
Created January 3, 2010 03:17
Show Gist options
  • Save arbales/267794 to your computer and use it in GitHub Desktop.
Save arbales/267794 to your computer and use it in GitHub Desktop.
class Table
# Checks if the table is available for a given time range.
#
# @param [Hash(Symbol => DateTime)] params
#
def available_at?(params)
if (params[:at].class != DateTime); raise ArgumentError, "Provide a DateTime for :at";end;
if (params[:ending].class != DateTime); raise ArgumentError, "Provide a DateTime for :ending";end;
return false if
(TableBooking.all(:at.lte => params[:at], :ending.gte => params[:ending]) +
TableBooking.all(:at.gte => params[:at], :at.lte => params[:ending]) +
TableBooking.all(:ending.gte => params[:at], :ending.lte => params[:ending])).count > 0
true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment