Last active
August 29, 2015 14:03
-
-
Save gtke/ef6e6a6b9897ebd171c5 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
def filter(input, filters = {}) | |
Array(input).find_all do |e| | |
filters.all? do |k, v| | |
filter_vals = v.to_s.split("|").map(&:strip) | |
if e.respond_to?('[]') && !e[k].nil? | |
filter_vals.include?(e[k].to_s) | |
elsif e.respond_to?(k) | |
filter_vals.include?(e.send(k.to_sym)) | |
else | |
false | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment