Skip to content

Instantly share code, notes, and snippets.

@vysogot
Created July 16, 2011 20:27
Show Gist options
  • Save vysogot/1086733 to your computer and use it in GitHub Desktop.
Save vysogot/1086733 to your computer and use it in GitHub Desktop.
Using FilterMatcher example
class PeopleMatcher
include FilterMatcher
attr_reader :db
def initialize(db, input)
@db, @input = db, input
end
def match
@input.each do |input|
collection = @db
filter_and_match collection, {
:by_name => input[:name],
:by_age => input[:age],
:by_homepage => input[:homepage]
}
end
end
private
def name_filter(collection, name)
collection.select { |element| element[:name] == name }
end
def age_filter(collection, age)
collection.select { |element| element[:age] == age}
end
def homepage_filter(collection, homepage)
collection.select { |element| element[:homepage] == homepage }
end
def element_matched(element)
element[:matched] = true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment