Class: MongoSearch::Matchers::LessThanMatcher
- Inherits:
-
Object
- Object
- MongoSearch::Matchers::LessThanMatcher
- Defined in:
- lib/mongo-search/matchers/less_than_matcher.rb
Instance Method Summary collapse
- #call(params) ⇒ Object
-
#initialize(attr, opts = nil) ⇒ LessThanMatcher
constructor
A new instance of LessThanMatcher.
Constructor Details
#initialize(attr, opts = nil) ⇒ LessThanMatcher
Returns a new instance of LessThanMatcher.
4 5 6 7 8 9 10 |
# File 'lib/mongo-search/matchers/less_than_matcher.rb', line 4 def initialize(attr, opts = nil) opts ||= {} @attr = attr @field = opts[:field] || attr @operator = opts[:equal] ? :$lte : :$lt @conv = Converters[opts[:type]] end |
Instance Method Details
#call(params) ⇒ Object
12 13 14 15 16 |
# File 'lib/mongo-search/matchers/less_than_matcher.rb', line 12 def call(params) filters = {} filters[@field] = {@operator => @conv.call(params[@attr])} if params[@attr] && !params[@attr].empty? filters end |