Class: ArrayCollection::CollectionFilter
- Inherits:
-
Object
- Object
- ArrayCollection::CollectionFilter
- Defined in:
- lib/array_collection/collection_filter.rb
Overview
filterable item using operators
Constant Summary collapse
- OPERATORS =
{ "=" => ->(a, b) { a == b }, "==" => ->(a, b) { a == b }, "!=" => ->(a, b) { a != b }, "<>" => ->(a, b) { a != b }, ">" => ->(a, b) { a > b }, ">=" => ->(a, b) { a >= b }, "<" => ->(a, b) { a < b }, "<=" => ->(a, b) { a <= b }, "LIKE" => ->(a, b) { a.to_s.include?(b.to_s) }, "NOT LIKE" => ->(a, b) { !a.to_s.include?(b.to_s) } }.freeze
Class Method Summary collapse
-
.apply_operator(operator, a, b) ⇒ Object
rubocop:disable Naming/MethodParameterName.
Class Method Details
.apply_operator(operator, a, b) ⇒ Object
rubocop:disable Naming/MethodParameterName
21 22 23 24 25 26 27 28 29 |
# File 'lib/array_collection/collection_filter.rb', line 21 def self.apply_operator(operator, a, b) # rubocop:disable Naming/MethodParameterName operator_lambda = OPERATORS[operator.upcase] unless operator_lambda raise UnsupportedOperator, "Unsupported operator: #{operator}, current supported operator: #{OPERATORS.keys}" end operator_lambda.call(a, b) end |