Class: Geospatial::Filter
- Inherits:
-
Object
- Object
- Geospatial::Filter
- Defined in:
- lib/geospatial/filter.rb
Defined Under Namespace
Classes: Range
Instance Attribute Summary collapse
-
#ranges ⇒ Object
readonly
Returns the value of attribute ranges.
Instance Method Summary collapse
- #add(prefix, order) ⇒ Object
- #apply(points) ⇒ Object (also: #&)
- #include?(point) ⇒ Boolean
-
#initialize ⇒ Filter
constructor
A new instance of Filter.
Constructor Details
#initialize ⇒ Filter
Returns a new instance of Filter.
55 56 57 |
# File 'lib/geospatial/filter.rb', line 55 def initialize @ranges = [] end |
Instance Attribute Details
#ranges ⇒ Object (readonly)
Returns the value of attribute ranges.
59 60 61 |
# File 'lib/geospatial/filter.rb', line 59 def ranges @ranges end |
Instance Method Details
#add(prefix, order) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/geospatial/filter.rb', line 61 def add(prefix, order) if last = @ranges.last raise ArgumentError.new("Cannot add non-sequential prefix") unless prefix > last.max end unless last = @ranges.last and last.(prefix, order) @ranges << Range.new(prefix, order) end end |
#apply(points) ⇒ Object Also known as: &
71 72 73 74 |
# File 'lib/geospatial/filter.rb', line 71 def apply(points) # This is a poor implementation. points.select{|point| @ranges.any?{|range| range.include?(point.hash)}} end |
#include?(point) ⇒ Boolean
78 79 80 |
# File 'lib/geospatial/filter.rb', line 78 def include?(point) @ranges.any?{|range| range.include?(point.hash)} end |