google_places 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "google_places"
6
- s.version = '0.0.6'
6
+ s.version = '0.0.7'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Marcel de Graaf"]
9
9
  s.email = ["mail@marceldegraaf.net"]
@@ -1,6 +1,6 @@
1
1
  module GooglePlaces
2
2
  class Spot
3
- attr_accessor :lat, :lng, :name, :icon, :reference, :vicinity, :types, :id, :formatted_phone_number, :formatted_address, :address_components, :rating, :url, :cid
3
+ attr_accessor :lat, :lng, :name, :icon, :reference, :vicinity, :types, :id, :formatted_phone_number, :international_phone_number, :formatted_address, :address_components, :street_number, :street, :city, :region, :postal_code, :country, :rating, :url, :cid, :website
4
4
 
5
5
  def self.list(lat, lng, api_key, options = {})
6
6
  radius = options.delete(:radius) || 200
@@ -55,20 +55,38 @@ module GooglePlaces
55
55
  end
56
56
 
57
57
  def initialize(json_result_object)
58
- @reference = json_result_object['reference']
59
- @vicinity = json_result_object['vicinity']
60
- @lat = json_result_object['geometry']['location']['lat']
61
- @lng = json_result_object['geometry']['location']['lng']
62
- @name = json_result_object['name']
63
- @icon = json_result_object['icon']
64
- @types = json_result_object['types']
65
- @id = json_result_object['id']
66
- @formatted_phone_number = json_result_object['formatted_phone_number']
67
- @formatted_address = json_result_object['formatted_address']
68
- @address_components = json_result_object['address_components']
69
- @rating = json_result_object['rating']
70
- @url = json_result_object['url']
71
- @cid = json_result_object['url'].to_i
58
+ @reference = json_result_object['reference']
59
+ @vicinity = json_result_object['vicinity']
60
+ @lat = json_result_object['geometry']['location']['lat']
61
+ @lng = json_result_object['geometry']['location']['lng']
62
+ @name = json_result_object['name']
63
+ @icon = json_result_object['icon']
64
+ @types = json_result_object['types']
65
+ @id = json_result_object['id']
66
+ @formatted_phone_number = json_result_object['formatted_phone_number']
67
+ @international_phone_number = json_result_object['international_phone_number']
68
+ @formatted_address = json_result_object['formatted_address']
69
+ @address_components = json_result_object['address_components']
70
+ @street_number = address_component(:street_number, 'short_name')
71
+ @street = address_component(:route, 'long_name')
72
+ @city = address_component(:locality, 'long_name')
73
+ @region = address_component(:administrative_area_level_1, 'long_name')
74
+ @postal_code = address_component(:postal_code, 'long_name')
75
+ @country = address_component(:country, 'long_name')
76
+ @rating = json_result_object['rating']
77
+ @url = json_result_object['url']
78
+ @cid = json_result_object['url'].to_i
79
+ @website = json_result_object['website']
80
+ end
81
+
82
+ def address_component(address_component_type, address_component_length)
83
+ if component = address_components_of_type(address_component_type)
84
+ component.first[address_component_length] unless component.first.nil?
85
+ end
86
+ end
87
+
88
+ def address_components_of_type(type)
89
+ @address_components.select{ |c| c['types'].include?(type.to_s) } unless @address_components.nil?
72
90
  end
73
91
 
74
92
  end
@@ -127,7 +127,7 @@ describe GooglePlaces::Spot do
127
127
  @spot.class.should == GooglePlaces::Spot
128
128
  end
129
129
 
130
- %w(reference vicinity lat lng name icon types id formatted_phone_number formatted_address address_components rating url types).each do |attribute|
130
+ %w(reference vicinity lat lng name icon types id formatted_phone_number international_phone_number formatted_address address_components street_number street city region postal_code country rating url types website).each do |attribute|
131
131
  it "should have the attribute: #{attribute}" do
132
132
  @spot.respond_to?(attribute).should == true
133
133
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_places
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marcel de Graaf
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-16 00:00:00 Z
18
+ date: 2011-12-19 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: httparty