Skip to content

Commit

Permalink
Implement exclusion of types. Fixes qpowell#7
Browse files Browse the repository at this point in the history
  • Loading branch information
marceldegraaf committed Jun 16, 2011
1 parent 631c7da commit ac4703a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
14 changes: 11 additions & 3 deletions README.rdoc
Expand Up @@ -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')
Expand Down
7 changes: 5 additions & 2 deletions lib/google_places/spot.rb
Expand Up @@ -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,
Expand All @@ -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 = {})
Expand Down
22 changes: 22 additions & 0 deletions spec/google_places/spot_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit ac4703a

Please sign in to comment.