Class: Geospatial::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/geospatial/filter.rb

Defined Under Namespace

Classes: Range

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFilter

Returns a new instance of Filter.



55
56
57
# File 'lib/geospatial/filter.rb', line 55

def initialize
	@ranges = []
end

Instance Attribute Details

#rangesObject (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.expand!(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

Returns:

  • (Boolean)


78
79
80
# File 'lib/geospatial/filter.rb', line 78

def include?(point)
	@ranges.any?{|range| range.include?(point.hash)}
end