Class: MongoSearch::Matchers::PartialMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo-search/matchers/partial_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(attr) ⇒ PartialMatcher

Returns a new instance of PartialMatcher.



4
5
6
# File 'lib/mongo-search/matchers/partial_matcher.rb', line 4

def initialize(attr)
  @attr = attr
end

Instance Method Details

#call(params) ⇒ Object



8
9
10
11
12
# File 'lib/mongo-search/matchers/partial_matcher.rb', line 8

def call(params)
  filters = {}
  filters[@attr] = /#{Regexp.escape(params[@attr])}/i if params[@attr] && !params[@attr].empty?
  filters
end