Skip to content

Instantly share code, notes, and snippets.

@JakubOboza
Created May 9, 2011 17:00
Show Gist options
  • Save JakubOboza/962885 to your computer and use it in GitHub Desktop.
Save JakubOboza/962885 to your computer and use it in GitHub Desktop.
module Filter
FILTERS = {
:not_cancelled => lambda {|booking| booking.cancelled == false },
# ...
}
def filter(rows, *filters)
booking = Booking.get_in_class(row['booking_reference'])
is_ok = true
filters.each do |filter_name|
if FILTERS.keys.include?(filter_name)
is_ok = is_ok && Filter::FILTERS[filter][booking]
#pick it up and call it
elsif filter_name.kind_of?(Proc)
is_ok = is_ok && filter_name[booking]
# you could also supply your own filter | probably not needed at all
else raise 'Error! Could not find filter'
end
end
is_ok
end
end
# filter(rows, :not_canceled, :not_working, :not_booked, :not_nuked)
@JakubOboza
Copy link
Author

added checkup of filter in FILTERS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment