Class: Rlocu::QueryBuilder::KeyValueCondition
- Inherits:
-
Object
- Object
- Rlocu::QueryBuilder::KeyValueCondition
- 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
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(key:, value:, condition: nil) ⇒ KeyValueCondition
constructor
A new instance of KeyValueCondition.
- #to_h ⇒ Object
Constructor Details
#initialize(key:, value:, condition: nil) ⇒ KeyValueCondition
Returns a new instance of KeyValueCondition.
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
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
21 22 23 |
# File 'lib/rlocu/query_builder.rb', line 21 def condition @condition end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
21 22 23 |
# File 'lib/rlocu/query_builder.rb', line 21 def key @key end |
#value ⇒ Object (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_h ⇒ Object
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 |