Skip to content

Instantly share code, notes, and snippets.

@gtke
Last active August 29, 2015 14:03
Show Gist options
  • Save gtke/ef6e6a6b9897ebd171c5 to your computer and use it in GitHub Desktop.
Save gtke/ef6e6a6b9897ebd171c5 to your computer and use it in GitHub Desktop.
სილამაზე
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