Class: Stretchy::Builders::FilterBuilder
- Inherits:
-
Object
- Object
- Stretchy::Builders::FilterBuilder
- Defined in:
- lib/stretchy/builders/filter_builder.rb
Instance Attribute Summary collapse
-
#exists ⇒ Object
readonly
Returns the value of attribute exists.
-
#geos ⇒ Object
readonly
Returns the value of attribute geos.
-
#inverse ⇒ Object
readonly
Returns the value of attribute inverse.
-
#ranges ⇒ Object
readonly
Returns the value of attribute ranges.
-
#should ⇒ Object
readonly
Returns the value of attribute should.
-
#terms ⇒ Object
readonly
Returns the value of attribute terms.
Instance Method Summary collapse
- #add_exists(fields) ⇒ Object
- #add_geo(field, distance, geo_point) ⇒ Object
- #add_range(field, options) ⇒ Object
- #add_terms(field, terms) ⇒ Object
- #any? ⇒ Boolean
-
#initialize(options = {}) ⇒ FilterBuilder
constructor
A new instance of FilterBuilder.
- #to_filters ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ FilterBuilder
Returns a new instance of FilterBuilder.
7 8 9 10 11 12 13 14 |
# File 'lib/stretchy/builders/filter_builder.rb', line 7 def initialize( = {}) @terms = Hash.new { [] } @ranges = Hash.new { [] } @geos = Hash.new { [] } @exists = [] @inverse = !![:inverse] @should = !![:should] end |
Instance Attribute Details
#exists ⇒ Object (readonly)
Returns the value of attribute exists.
5 6 7 |
# File 'lib/stretchy/builders/filter_builder.rb', line 5 def exists @exists end |
#geos ⇒ Object (readonly)
Returns the value of attribute geos.
5 6 7 |
# File 'lib/stretchy/builders/filter_builder.rb', line 5 def geos @geos end |
#inverse ⇒ Object (readonly)
Returns the value of attribute inverse.
5 6 7 |
# File 'lib/stretchy/builders/filter_builder.rb', line 5 def inverse @inverse end |
#ranges ⇒ Object (readonly)
Returns the value of attribute ranges.
5 6 7 |
# File 'lib/stretchy/builders/filter_builder.rb', line 5 def ranges @ranges end |
#should ⇒ Object (readonly)
Returns the value of attribute should.
5 6 7 |
# File 'lib/stretchy/builders/filter_builder.rb', line 5 def should @should end |
#terms ⇒ Object (readonly)
Returns the value of attribute terms.
5 6 7 |
# File 'lib/stretchy/builders/filter_builder.rb', line 5 def terms @terms end |
Instance Method Details
#add_exists(fields) ⇒ Object
33 34 35 36 |
# File 'lib/stretchy/builders/filter_builder.rb', line 33 def add_exists(fields) @exists += clean_string_array(fields) @exists.uniq! end |
#add_geo(field, distance, geo_point) ⇒ Object
29 30 31 |
# File 'lib/stretchy/builders/filter_builder.rb', line 29 def add_geo(field, distance, geo_point) @geos[field] = Filters::GeoFilter.new(field, distance, geo_point) end |
#add_range(field, options) ⇒ Object
25 26 27 |
# File 'lib/stretchy/builders/filter_builder.rb', line 25 def add_range(field, ) @ranges[field] = Filters::RangeFilter.new(field, ) end |
#add_terms(field, terms) ⇒ Object
20 21 22 23 |
# File 'lib/stretchy/builders/filter_builder.rb', line 20 def add_terms(field, terms) @terms[field] += Array(terms) @terms[field].uniq! end |
#any? ⇒ Boolean
16 17 18 |
# File 'lib/stretchy/builders/filter_builder.rb', line 16 def any? @terms.any? || @ranges.any? || @geos.any? || @exists.any? end |
#to_filters ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/stretchy/builders/filter_builder.rb', line 38 def to_filters filters = @ranges.values + @geos.values filters += @terms.map do |field, values| Filters::TermsFilter.new(field, values) end filters += @exists.map {|field| Filters::ExistsFilter.new(field) } filters end |