Class: Boolminot::Clauses::Range
- Defined in:
- lib/boolminot/clauses/range.rb
Instance Attribute Summary collapse
-
#bounds ⇒ Object
readonly
Returns the value of attribute bounds.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #and(other) ⇒ Object
- #and_with_range(range_clause) ⇒ Object
-
#initialize(field, bounds, opts = {}) ⇒ Range
constructor
A new instance of Range.
- #lower_bound ⇒ Object
- #upper_bound ⇒ Object
Methods included from Base::ClassMethods
Methods included from Base::InstanceMethods
#satisfied_by?, #to_elasticsearch, #to_elasticsearch_negated, #to_raw_bool
Constructor Details
#initialize(field, bounds, opts = {}) ⇒ Range
Returns a new instance of Range.
6 7 8 9 10 11 |
# File 'lib/boolminot/clauses/range.rb', line 6 def initialize(field, bounds, opts = {}) @field = field.to_sym @bounds = normalized(bounds) @opts = opts validate_consistency end |
Instance Attribute Details
#bounds ⇒ Object (readonly)
Returns the value of attribute bounds.
4 5 6 |
# File 'lib/boolminot/clauses/range.rb', line 4 def bounds @bounds end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
4 5 6 |
# File 'lib/boolminot/clauses/range.rb', line 4 def field @field end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
4 5 6 |
# File 'lib/boolminot/clauses/range.rb', line 4 def opts @opts end |
Instance Method Details
#and(other) ⇒ Object
21 22 23 |
# File 'lib/boolminot/clauses/range.rb', line 21 def and(other) other.and_with_range(self) end |
#and_with_range(range_clause) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/boolminot/clauses/range.rb', line 25 def and_with_range(range_clause) return super unless opts.empty? && range_clause.opts.empty? return super unless field == range_clause.field new_bounds = bounds.merge(range_clause.bounds) { return super } valid_bounds = Helpers::RangeBoundsValidator.new(new_bounds).valid? return super unless valid_bounds clause_factory.range(field, new_bounds) end |
#lower_bound ⇒ Object
13 14 15 |
# File 'lib/boolminot/clauses/range.rb', line 13 def lower_bound bounds[:gt] || bounds[:gte] end |
#upper_bound ⇒ Object
17 18 19 |
# File 'lib/boolminot/clauses/range.rb', line 17 def upper_bound bounds[:lt] || bounds[:lte] end |