Class: Elasticband::Filter::Range
- Inherits:
-
Elasticband::Filter
- Object
- Elasticband::Filter
- Elasticband::Filter::Range
- Defined in:
- lib/elasticband/filter/range.rb
Constant Summary collapse
- RANGES =
%i(gt gteq lt lteq).freeze
Constants inherited from Elasticband::Filter
Instance Attribute Summary collapse
-
#field ⇒ Object
Returns the value of attribute field.
-
#ranges ⇒ Object
Returns the value of attribute ranges.
Attributes inherited from Elasticband::Filter
Instance Method Summary collapse
-
#initialize(field, ranges) ⇒ Range
constructor
A new instance of Range.
- #parsed_ranges ⇒ Object
- #permitted_ranges(ranges) ⇒ Object
- #to_h ⇒ Object
Methods inherited from Elasticband::Filter
Constructor Details
#initialize(field, ranges) ⇒ Range
Returns a new instance of Range.
8 9 10 11 |
# File 'lib/elasticband/filter/range.rb', line 8 def initialize(field, ranges) self.field = field.to_sym self.ranges = permitted_ranges(ranges) end |
Instance Attribute Details
#field ⇒ Object
Returns the value of attribute field.
4 5 6 |
# File 'lib/elasticband/filter/range.rb', line 4 def field @field end |
#ranges ⇒ Object
Returns the value of attribute ranges.
4 5 6 |
# File 'lib/elasticband/filter/range.rb', line 4 def ranges @ranges end |
Instance Method Details
#parsed_ranges ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/elasticband/filter/range.rb', line 21 def parsed_ranges translated_range = ranges.dup translated_range[:gte] = translated_range.delete(:gteq) if translated_range.key?(:gteq) translated_range[:lte] = translated_range.delete(:lteq) if translated_range.key?(:lteq) translated_range end |
#permitted_ranges(ranges) ⇒ Object
17 18 19 |
# File 'lib/elasticband/filter/range.rb', line 17 def permitted_ranges(ranges) ranges.keep_if { |key, _| RANGES.include?(key) } end |
#to_h ⇒ Object
13 14 15 |
# File 'lib/elasticband/filter/range.rb', line 13 def to_h { range: { field => parsed_ranges } } end |