Class: SqlQueryExecutor::Operators::Between

Inherits:
Base
  • Object
show all
Defined in:
lib/sql_query_executor/operators/between.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from SqlQueryExecutor::Operators::Base

Instance Method Details

#execute!Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sql_query_executor/operators/between.rb', line 6

def execute!
  @collection.select do |record|
    value = convert_value(record.send(@field).to_s)

    if value.class != @value.first.class
      false
    else
      greather_than = value.send('>=', @value.first)
      smaller_than  = value.send('<=', @value.last)

      greather_than && smaller_than
    end
  end
end

#selectorObject



21
22
23
# File 'lib/sql_query_executor/operators/between.rb', line 21

def selector
  { @field => { "$gte" => @value.first, "$lte" => @value.last }}
end