google_geocoding 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{google_geocoding}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rodrigo Kochenburger"]
@@ -6,7 +6,7 @@ module GoogleGeocoding
6
6
  def initialize(resp_body)
7
7
  @data = JSON.parse(resp_body)
8
8
  end
9
-
9
+
10
10
  # Return the status code included in the server response.
11
11
  #
12
12
  # @return [Integer]
@@ -14,17 +14,17 @@ module GoogleGeocoding
14
14
  def status_code
15
15
  Integer(@data["Status"]["code"])
16
16
  end
17
-
17
+
18
18
  # Return whether response successfully resolved the geolocation
19
19
  def success?
20
20
  status_code == 200
21
21
  end
22
-
22
+
23
23
  # Return whether response failed to resolved the geolocation
24
24
  def failure?
25
25
  !success?
26
26
  end
27
-
27
+
28
28
  # Return the placemarks included in the response.
29
29
  #
30
30
  # @return [Array<Placemark>]
@@ -33,7 +33,7 @@ module GoogleGeocoding
33
33
  raise Errors::ServiceError.build(status_code)
34
34
  else
35
35
  placemarks = []
36
-
36
+
37
37
  @data["Placemark"].each do |placemark_data|
38
38
  details = placemark_data["AddressDetails"]
39
39
  coordinates = placemark_data["Point"]["coordinates"][2..1]
@@ -41,37 +41,30 @@ module GoogleGeocoding
41
41
  placemark = Placemark.new
42
42
  placemark.accurracy = accurracy
43
43
  placemark.coordinates = coordinates
44
-
45
- next if accurracy >= 9
46
44
 
47
- if accurracy >= 1
48
- country = details["Country"]
45
+ if country = details["Country"]
49
46
  placemark.country_name = country["CountryName"],
50
47
  placemark.country_code = country["CountryNameCode"]
51
-
52
- if accurracy >= 2
53
- admarea = country["AdministrativeArea"]
48
+
49
+ if admarea = country["AdministrativeArea"]
54
50
  placemark.region = admarea["AdministrativeAreaName"]
55
-
56
- if accurracy >= 3
57
- subadmarea = admarea["SubAdministrativeArea"]
58
-
59
- if accurracy >= 4
60
- locality = subadmarea ? subadmarea["Locality"] : admarea["Locality"]
61
- placemark.city = locality["LocalityName"]
62
-
63
- if accurracy >= 5
64
- placemark.postal_code = locality["PostalCode"]["PostalCodeNumber"]
65
- end
66
-
67
- if accurracy >= 6
68
- placemark.street = locality["Thoroughfare"]["ThoroughfareName"]
69
- end
51
+ subadmarea = admarea["SubAdministrativeArea"]
52
+ locality = subadmarea ? subadmarea["Locality"] : admarea["Locality"]
53
+
54
+ if locality
55
+ placemark.city = locality["LocalityName"]
56
+
57
+ if postal_code = locality["PostalCode"]
58
+ placemark.postal_code = postal_code["PostalCodeNumber"]
59
+ end
60
+
61
+ if thoroughfare = locality["Thoroughfare"]
62
+ placemark.street = thoroughfare["ThoroughfareName"]
70
63
  end
71
64
  end
72
65
  end
73
66
  end
74
-
67
+
75
68
  placemarks << placemark
76
69
  end
77
70
  placemarks
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_geocoding
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Kochenburger