Class: Stretchy::Builders::WhereBuilder
- Inherits:
-
Object
- Object
- Stretchy::Builders::WhereBuilder
- Extended by:
- Forwardable
- Defined in:
- lib/stretchy/builders/where_builder.rb
Instance Attribute Summary collapse
-
#must ⇒ Object
Returns the value of attribute must.
-
#must_not ⇒ Object
Returns the value of attribute must_not.
-
#should ⇒ Object
Returns the value of attribute should.
-
#should_not ⇒ Object
Returns the value of attribute should_not.
Instance Method Summary collapse
- #add_geo(field, distance, options = {}) ⇒ Object
- #add_param(field, param, options = {}) ⇒ Object
- #add_range(field, options = {}) ⇒ Object
- #any? ⇒ Boolean
-
#initialize(options = {}) ⇒ WhereBuilder
constructor
A new instance of WhereBuilder.
- #to_filter ⇒ Object
- #use_bool? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ WhereBuilder
Returns a new instance of WhereBuilder.
9 10 11 12 13 14 |
# File 'lib/stretchy/builders/where_builder.rb', line 9 def initialize( = {}) @must = FilterBuilder.new @must_not = FilterBuilder.new(inverse: true) @should = FilterBuilder.new(should: true) @should_not = FilterBuilder.new(inverse: true, should: true) end |
Instance Attribute Details
#must ⇒ Object
Returns the value of attribute must.
7 8 9 |
# File 'lib/stretchy/builders/where_builder.rb', line 7 def must @must end |
#must_not ⇒ Object
Returns the value of attribute must_not.
7 8 9 |
# File 'lib/stretchy/builders/where_builder.rb', line 7 def must_not @must_not end |
#should ⇒ Object
Returns the value of attribute should.
7 8 9 |
# File 'lib/stretchy/builders/where_builder.rb', line 7 def should @should end |
#should_not ⇒ Object
Returns the value of attribute should_not.
7 8 9 |
# File 'lib/stretchy/builders/where_builder.rb', line 7 def should_not @should_not end |
Instance Method Details
#add_geo(field, distance, options = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/stretchy/builders/where_builder.rb', line 35 def add_geo(field, distance, = {}) if [:geo_point] geo_point = Types::GeoPoint.new([:geo_point]) else geo_point = Types::GeoPoint.new() end ().add_geo(field, distance, geo_point) end |
#add_param(field, param, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/stretchy/builders/where_builder.rb', line 24 def add_param(field, param, = {}) case param when nil (.merge(inverse: ![:inverse])).add_exists(field) when ::Range, Types::Range ().add_range(field, param) else ().add_terms(field, param) end end |
#add_range(field, options = {}) ⇒ Object
45 46 47 |
# File 'lib/stretchy/builders/where_builder.rb', line 45 def add_range(field, = {}) ().add_range(field, ) end |
#any? ⇒ Boolean
16 17 18 |
# File 'lib/stretchy/builders/where_builder.rb', line 16 def any? must.any? || must_not.any? || should.any? || should_not.any? end |
#to_filter ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/stretchy/builders/where_builder.rb', line 49 def to_filter if use_bool? bool_filter elsif must.any? and_filter elsif must_not.any? not_filter else nil end end |
#use_bool? ⇒ Boolean
20 21 22 |
# File 'lib/stretchy/builders/where_builder.rb', line 20 def use_bool? (must.any? && must_not.any?) || should.any? || should_not.any? end |