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 ⇒ FilterBuilder
constructor
A new instance of FilterBuilder.
- #to_filters ⇒ Object
Constructor Details
#initialize ⇒ FilterBuilder
Returns a new instance of FilterBuilder.
7 8 9 10 11 12 |
# File 'lib/stretchy/builders/filter_builder.rb', line 7 def initialize @terms = Hash.new { [] } @ranges = Hash.new { [] } @geos = Hash.new { [] } @exists = [] 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
31 32 33 34 |
# File 'lib/stretchy/builders/filter_builder.rb', line 31 def add_exists(fields) @exists += clean_string_array(fields) @exists.uniq! end |
#add_geo(field, distance, geo_point) ⇒ Object
27 28 29 |
# File 'lib/stretchy/builders/filter_builder.rb', line 27 def add_geo(field, distance, geo_point) @geos[field] = Filters::GeoFilter.new(field, distance, geo_point) end |
#add_range(field, options) ⇒ Object
23 24 25 |
# File 'lib/stretchy/builders/filter_builder.rb', line 23 def add_range(field, ) @ranges[field] = Filters::RangeFilter.new(field, ) end |
#add_terms(field, terms) ⇒ Object
18 19 20 21 |
# File 'lib/stretchy/builders/filter_builder.rb', line 18 def add_terms(field, terms) @terms[field] += Array(terms) @terms[field].uniq! end |
#any? ⇒ Boolean
14 15 16 |
# File 'lib/stretchy/builders/filter_builder.rb', line 14 def any? @terms.any? || @ranges.any? || @geos.any? || @exists.any? end |
#to_filters ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/stretchy/builders/filter_builder.rb', line 36 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 |