Class: SqlQueryExecutor::Operators::Default
- Defined in:
- lib/sql_query_executor/operators/default.rb
Constant Summary collapse
- SELECTORS =
{ "==" => nil, ">" => "$gt", "<" => "$lt", ">=" => "$gte", "<=" => "$lte", "!=" => "$ne" }
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(query, collection) ⇒ Default
constructor
A new instance of Default.
- #selector ⇒ Object
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 |
#selector ⇒ Object
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 |