Class: MongoSearch::Matchers::GreaterThanMatcher

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

Instance Method Summary collapse

Constructor Details

#initialize(attr, opts = nil) ⇒ GreaterThanMatcher

Returns a new instance of GreaterThanMatcher.



4
5
6
7
8
9
10
# File 'lib/mongo-search/matchers/greater_than_matcher.rb', line 4

def initialize(attr, opts = nil)
  opts ||= {}
  @attr     = attr
  @field    = opts[:field] || attr
  @operator = opts[:equal] ? :$gte : :$gt
  @conv     = Converters[opts[:type]]
end

Instance Method Details

#call(params) ⇒ Object



12
13
14
15
16
# File 'lib/mongo-search/matchers/greater_than_matcher.rb', line 12

def call(params)
  filters = {}
  filters[@field] = {@operator => @conv.call(params[@attr])} if params[@attr] && !params[@attr].empty?
  filters
end