Class: Rlocu::QueryBuilder::KeyValueCondition

Inherits:
Object
  • Object
show all
Defined in:
lib/rlocu/query_builder.rb

Constant Summary collapse

ValidConditions =
%w{$present $gt $lt $ge $le $contains_any $contains_all $contains_none $in_lat_lng_bbox $in_lat_lng_radius} << nil

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, value:, condition: nil) ⇒ KeyValueCondition

Returns a new instance of KeyValueCondition.

Raises:

  • (ArgumentError)


23
24
25
26
27
28
# File 'lib/rlocu/query_builder.rb', line 23

def initialize(key:, value:, condition: nil)
  @key = key
  @value = value
  @condition = condition
  raise ArgumentError unless valid?
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition.



21
22
23
# File 'lib/rlocu/query_builder.rb', line 21

def condition
  @condition
end

#keyObject (readonly)

Returns the value of attribute key.



21
22
23
# File 'lib/rlocu/query_builder.rb', line 21

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value.



21
22
23
# File 'lib/rlocu/query_builder.rb', line 21

def value
  @value
end

Instance Method Details

#to_hObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rlocu/query_builder.rb', line 30

def to_h
  if condition
    if value.is_a?(Utilities::LatLongRadius)
      {key => {'geo' => {condition => value.to_a}}}
    elsif key == 'categories'
      {key => {'str_id' => {condition => value}}}
    else
      {key => {condition => value}}
    end
  else
    {key => value}
  end
end