Permalink
Browse files

Implement exclusion of types. Fixes #7

  • Loading branch information...
1 parent 631c7da commit ac4703af9727c15875a7bf41d4469301c48bfe60 @marceldegraaf marceldegraaf committed Jun 16, 2011
Showing with 38 additions and 5 deletions.
  1. +11 −3 README.rdoc
  2. +5 −2 lib/google_places/spot.rb
  3. +22 −0 spec/google_places/spot_spec.rb
View
@@ -53,15 +53,23 @@ Then retrieve a list of spots:
Search by a specific type:
@client.spots(-33.8670522, 151.1957362, :types => 'restaurant')
-
+
Search by multiple types:
@client.spots(-33.8670522, 151.1957362, :types => ['restaurant','food'])
-
+
+Search by multiple types but exclude one type:
+
+ @client.spots(-33.8670522, 151.1957362, :types => ['restaurant','food'], :exclude => 'cafe')
+
+Search by multiple types but exclude multiple types:
+
+ @client.spots(-33.8670522, 151.1957362, :types => ['restaurant','food'], :exclude => ['cafe', 'establishment'])
+
Search by name:
@client.spots(-33.8670522, 151.1957362, :name => 'italian')
-
+
Search by name *and* type:
@client.spots(-33.8670522, 151.1957362, :name => 'italian', :types => 'restaurant')
@@ -8,6 +8,9 @@ def self.list(lat, lng, api_key, options = {})
types = options.delete(:types)
name = options.delete(:name)
location = Location.new(lat, lng)
+ exclude = options.delete(:exclude) || []
+
+ exclude = [exclude] unless exclude.is_a?(Array)
options = {
:location => location.format,
@@ -25,8 +28,8 @@ def self.list(lat, lng, api_key, options = {})
response = Request.spots(options)
response['results'].map do |result|
- self.new(result)
- end
+ self.new(result) if (result['types'] & exclude) == []
+ end.compact
end
def self.find(reference, api_key, options = {})
@@ -92,6 +92,28 @@
end
end
end
+
+ describe 'searching by types with exclusion' do
+ use_vcr_cassette 'list_spots_with_types_and_exclusion'
+
+ it 'should exclude spots with type "restaurant"' do
+ @collection = GooglePlaces::Spot.list(@lat, @lng, api_key, :radius => @radius, :sensor => @sensor, :types => ['food','establishment'], :exclude => 'restaurant')
+
+ @collection.map(&:types).each do |types|
+ types.should_not include('restaurant')
+ end
+ end
+
+ it 'should exclude spots with type "restaurant" and "cafe"' do
+ @collection = GooglePlaces::Spot.list(@lat, @lng, api_key, :radius => @radius, :sensor => @sensor, :types => ['food','establishment'], :exclude => ['restaurant', 'cafe'])
+
+ @collection.map(&:types).each do |types|
+ types.should_not include('restaurant')
+ types.should_not include('cafe')
+ end
+ end
+ end
+
end
context 'Find a single spot' do

0 comments on commit ac4703a

Please sign in to comment.