Created
May 9, 2011 17:00
-
-
Save JakubOboza/962885 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
added checkup of filter in FILTERS