Class: Caoutsearch::Filter::Range
- Defined in:
- lib/caoutsearch/filter/range.rb
Instance Attribute Summary
Attributes inherited from Base
#key, #options, #original_value, #type
Instance Method Summary collapse
Methods inherited from Base
#as_json, call, #initialize, #value
Constructor Details
This class inherits a constructor from Caoutsearch::Filter::Base
Instance Method Details
#cast_value_with_overflow(value, type) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/caoutsearch/filter/range.rb', line 19 def cast_value_with_overflow(value, type) cast_value(value) rescue Caoutsearch::Search::ValueOverflow => e raise(e) unless type == e.type e.limit end |
#filter ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/caoutsearch/filter/range.rb', line 6 def filter original_values.map do |value| case value when />(.+)/ then {range: {key => {gt: cast_value_with_overflow($1, :lower)}}} when /<(.+)/ then {range: {key => {lt: cast_value_with_overflow($1, :upper)}}} when /≥(.+)/ then {range: {key => {gte: cast_value_with_overflow($1, :lower)}}} when /≤(.+)/ then {range: {key => {lte: cast_value_with_overflow($1, :upper)}}} when /(.+)-(.+)/ then {range: {key => {gte: cast_value_with_overflow($1, :lower), lte: cast_value_with_overflow($2, :upper)}}} else {term: {key => cast_value(value)}} end end end |