Created
July 16, 2011 20:27
-
-
Save vysogot/1086733 to your computer and use it in GitHub Desktop.
Using FilterMatcher example
This file contains 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
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