Class: Elasticated::Conditions::RangeCondition

Inherits:
StandardCondition show all
Defined in:
lib/elasticated/conditions/range_condition.rb

Instance Attribute Summary collapse

Attributes inherited from StandardCondition

#field, #opts

Instance Method Summary collapse

Methods included from Mixins::Clonable

#==, #clone

Methods included from Mixins::Inspectionable

#inspect, #text_for_inspect

Constructor Details

#initialize(field, body, opts = {}) ⇒ RangeCondition

Returns a new instance of RangeCondition.



9
10
11
12
# File 'lib/elasticated/conditions/range_condition.rb', line 9

def initialize(field, body, opts={})
  super(field, opts)
  self.body = Hash::Indifferent.new body
end

Instance Attribute Details

#bodyObject

example: RangeCondition.new :age, gte: 18, lt: 40



7
8
9
# File 'lib/elasticated/conditions/range_condition.rb', line 7

def body
  @body
end

Instance Method Details

#buildObject



14
15
16
# File 'lib/elasticated/conditions/range_condition.rb', line 14

def build
  { range: { field => body }.merge(opts) }
end

#fill_delimiter(field_delimiter) ⇒ Object



18
19
20
21
22
23
# File 'lib/elasticated/conditions/range_condition.rb', line 18

def fill_delimiter(field_delimiter)
  minimum_value = body[:gt] || body[:gte]
  field_delimiter.set_minimum field, minimum_value
  maximum_value = body[:lt] || body[:lte]
  field_delimiter.set_maximum field, maximum_value
end