Class: Boolminot::Clauses::Range

Inherits:
Base
  • Object
show all
Defined in:
lib/boolminot/clauses/range.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base::ClassMethods

#predicate_factory

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

#boundsObject (readonly)

Returns the value of attribute bounds.



4
5
6
# File 'lib/boolminot/clauses/range.rb', line 4

def bounds
  @bounds
end

#fieldObject (readonly)

Returns the value of attribute field.



4
5
6
# File 'lib/boolminot/clauses/range.rb', line 4

def field
  @field
end

#optsObject (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_boundObject



13
14
15
# File 'lib/boolminot/clauses/range.rb', line 13

def lower_bound
  bounds[:gt] || bounds[:gte]
end

#upper_boundObject



17
18
19
# File 'lib/boolminot/clauses/range.rb', line 17

def upper_bound
  bounds[:lt] || bounds[:lte]
end