Class: SqlQueryExecutor::Operators::Default

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

Constant Summary collapse

SELECTORS =
{
  "=="      => nil,
  ">"       => "$gt",
  "<"       => "$lt",
  ">="      => "$gte",
  "<="      => "$lte",
  "!="      => "$ne"
}

Instance Method Summary collapse

Constructor Details

#initialize(query, collection) ⇒ Default

Returns a new instance of Default.



15
16
17
18
# File 'lib/sql_query_executor/operators/default.rb', line 15

def initialize(query, collection)
  super
  convert_operator
end

Instance Method Details

#execute!Object



20
21
22
23
24
25
26
# File 'lib/sql_query_executor/operators/default.rb', line 20

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

    value.send(@operator, @value) rescue false
  end
end

#selectorObject



28
29
30
31
32
# File 'lib/sql_query_executor/operators/default.rb', line 28

def selector
  operator = SELECTORS[@operator]

  { @field => operator ? {operator => @value} : @value}
end