class Boolminot::Clauses::Range
Attributes
bounds[R]
field[R]
opts[R]
Public Class Methods
new(field, bounds, opts = {})
click to toggle source
# 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
Public Instance Methods
and(other)
click to toggle source
# File lib/boolminot/clauses/range.rb, line 21 def and(other) other.and_with_range(self) end
and_with_range(range_clause)
click to toggle source
Calls superclass method
# 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()
click to toggle source
# File lib/boolminot/clauses/range.rb, line 13 def lower_bound bounds[:gt] || bounds[:gte] end
upper_bound()
click to toggle source
# File lib/boolminot/clauses/range.rb, line 17 def upper_bound bounds[:lt] || bounds[:lte] end
Private Instance Methods
body()
click to toggle source
# File lib/boolminot/clauses/range.rb, line 43 def body bounds.merge(opts) end
normalized(hash)
click to toggle source
# File lib/boolminot/clauses/range.rb, line 47 def normalized(hash) hash.each_with_object(hash.class.new) do |(k, v), h| h[k.to_sym] = v end end
to_elasticsearch_in_filter_context()
click to toggle source
# File lib/boolminot/clauses/range.rb, line 39 def to_elasticsearch_in_filter_context { type => { field => body } } end
validate_consistency()
click to toggle source
# File lib/boolminot/clauses/range.rb, line 53 def validate_consistency valid = Helpers::RangeBoundsValidator.new(bounds).valid? raise ArgumentError, "invalid range bounds: #{bounds}" unless valid end