Class: Underpass::Filter
- Inherits:
-
Object
- Object
- Underpass::Filter
- Defined in:
- lib/underpass/filter.rb
Overview
Post-query filtering of Feature objects by tag properties.
Instance Method Summary collapse
-
#initialize(features) ⇒ Filter
constructor
Creates a new filter for the given features.
-
#reject(conditions = {}) ⇒ Array<Feature>
Returns features that do not match any of the given conditions.
-
#where(conditions = {}) ⇒ Array<Feature>
Returns features whose properties match all given conditions.
Constructor Details
#initialize(features) ⇒ Filter
Creates a new filter for the given features.
13 14 15 |
# File 'lib/underpass/filter.rb', line 13 def initialize(features) @features = features end |
Instance Method Details
#reject(conditions = {}) ⇒ Array<Feature>
Returns features that do not match any of the given conditions.
40 41 42 43 44 |
# File 'lib/underpass/filter.rb', line 40 def reject(conditions = {}) @features.reject do |feature| conditions.any? { |key, value| feature.properties[key] == value.to_s } end end |
#where(conditions = {}) ⇒ Array<Feature>
Returns features whose properties match all given conditions.
Conditions can be exact values, regular expressions, or arrays of values.
30 31 32 33 34 |
# File 'lib/underpass/filter.rb', line 30 def where(conditions = {}) @features.select do |feature| conditions.all? { |key, value| match_condition?(feature.properties[key], value) } end end |