geocoder 1.6.4 → 1.6.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e4c449a8a83ae4e05f107ca65e5b0c17330c775ee47e0015705cb5a557b37af
4
- data.tar.gz: 588192a50b794f6e953f46491b36680e0bd8629a05b236a049669a377ff12fde
3
+ metadata.gz: 4ba8acaf931aa2da26a0d1d68aef25d8ea2c30c7f532e996b5ad29da100ef135
4
+ data.tar.gz: 379b182609b60c49c10c5cce6c436ae80446790466174c0a592a10ca6ffd41c3
5
5
  SHA512:
6
- metadata.gz: 2afedac2b198f7cea780fe496178d1188dc4b79f4d845322dbb865da6e23681d145708d366db3c93aa88aa5a1736f3dc2a0ec04a022054d12ccb853d7ba03443
7
- data.tar.gz: 5926d851a342d3fad0cb993affba56d689d58d8c5584966b290e2e0da60d7bc597ed60bc23194e1c0fb6644310f0121a5ac157ccf0743182b15dffe733141656
6
+ metadata.gz: 6a31567336ce0f94c0c03640dbc94c3117b7d076af94afc885728405d32aa52bbbbd31631b05b0165c04c235dfb51331d349c4e55da7866f451f2871ba4286de
7
+ data.tar.gz: aa6f58798d354b2e526b23d64b8c7c0c297649d5ddcd9a57198585470ac23b055c604302153cee203b19bed8d3b39a1c49018aafb3df72d7ec816c53e452fc4e
data/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@ Changelog
3
3
 
4
4
  Major changes to Geocoder for each release. Please see the Git log for complete list of changes.
5
5
 
6
+ 1.6.5 (2020 Feb 10)
7
+ -------------------
8
+ * Fix backward coordinates bug in NationaalregisterNl lookup (thanks github.com/Marthyn).
9
+ * Allow removal of single stubs in test mode (thanks github.com/jmmastey).
10
+ * Improve results for :ban_data_gouv_fr lookup (thanks github.com/Intrepidd).
11
+
6
12
  1.6.4 (2020 Oct 6)
7
13
  -------------------
8
14
  * Various updates in response to geocoding API changes.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2020 Alex Reisner
1
+ Copyright (c) 2009-2021 Alex Reisner
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -213,7 +213,7 @@ Some common options are:
213
213
  # set default units to kilometers:
214
214
  units: :km,
215
215
 
216
- # caching (see [below](#caching) for details):
216
+ # caching (see Caching section below for details):
217
217
  cache: Redis.new,
218
218
  cache_prefix: "..."
219
219
 
@@ -532,10 +532,14 @@ With the above stub defined, any query for "New York, NY" will return the result
532
532
  ]
533
533
  )
534
534
 
535
+ You may also delete a single stub, or reset all stubs _including the default stub_:
536
+
537
+ Geocoder::Lookup::Test.delete_stub('New York, NY')
538
+ Geocoder::Lookup::Test.reset
539
+
535
540
  Notes:
536
541
 
537
542
  - Keys must be strings (not symbols) when calling `add_stub` or `set_default_stub`. For example `'country' =>` not `:country =>`.
538
- - To clear stubs (e.g. prior to another spec), use `Geocoder::Lookup::Test.reset`. This will clear all stubs _including the default stub_.
539
543
  - The stubbed result objects returned by the Test lookup do not support all the methods real result objects do. If you need to test interaction with real results it may be better to use an external stubbing tool and something like WebMock or VCR to prevent network calls.
540
544
 
541
545
 
@@ -676,29 +680,4 @@ If anyone has a more elegant solution to this problem I am very interested in se
676
680
  The `near` method will not look across the 180th meridian to find objects close to a given point. In practice this is rarely an issue outside of New Zealand and certain surrounding islands. This problem does not exist with the zero-meridian. The problem is due to a shortcoming of the Haversine formula which Geocoder uses to calculate distances.
677
681
 
678
682
 
679
- Reporting Issues
680
- ----------------
681
-
682
- When reporting an issue, please list the version of Geocoder you are using and any relevant information about your application (Rails version, database type and version, etc). Please describe as specifically as you can what behavior you are seeing (eg: an error message? a nil return value?).
683
-
684
- Please DO NOT use GitHub issues to ask questions about how to use Geocoder. Sites like [StackOverflow](http://www.stackoverflow.com/) are a better forum for such discussions.
685
-
686
-
687
- Contributing
688
- ------------
689
-
690
- Contributions are welcome via Github pull requests. If you are new to the project and looking for a way to get involved, try picking up an issue with a "beginner-task" label. Hints about what needs to be done are usually provided.
691
-
692
- For all contributions, please respect the following guidelines:
693
-
694
- * Each pull request should implement ONE feature or bugfix. If you want to add or fix more than one thing, submit more than one pull request.
695
- * Do not commit changes to files that are irrelevant to your feature or bugfix (eg: `.gitignore`).
696
- * Do not add dependencies on other gems.
697
- * Do not add unnecessary `require` statements which could cause LoadErrors on certain systems.
698
- * Remember: Geocoder needs to run outside of Rails. Don't assume things like ActiveSupport are available.
699
- * Be willing to accept criticism and work on improving your code; Geocoder is used by thousands of developers and care must be taken not to introduce bugs.
700
- * Be aware that the pull request review process is not immediate, and is generally proportional to the size of the pull request.
701
- * If your pull request is merged, please do not ask for an immediate release of the gem. There are many factors contributing to when releases occur (remember that they affect thousands of apps with Geocoder in their Gemfiles). If necessary, please install from the Github source until the next official release.
702
-
703
-
704
- Copyright :copyright: 2009-2020 Alex Reisner, released under the MIT license.
683
+ Copyright :copyright: 2009-2021 Alex Reisner, released under the MIT license.
@@ -30,7 +30,13 @@ module Geocoder::Lookup
30
30
  def results(query)
31
31
  if configuration[:file]
32
32
  geoip_class = RUBY_PLATFORM == "java" ? JGeoIP : GeoIP
33
- result = geoip_class.new(configuration[:file]).city(query.to_s)
33
+ geoip_instance = geoip_class.new(configuration[:file])
34
+ result =
35
+ if configuration[:package] == :country
36
+ geoip_instance.country(query.to_s)
37
+ else
38
+ geoip_instance.city(query.to_s)
39
+ end
34
40
  result.nil? ? [] : [encode_hash(result.to_hash)]
35
41
  elsif configuration[:package] == :city
36
42
  addr = IPAddr.new(query.text).to_i
@@ -28,6 +28,10 @@ module Geocoder
28
28
  @stubs ||= {}
29
29
  end
30
30
 
31
+ def self.delete_stub(query_text)
32
+ stubs.delete(query_text)
33
+ end
34
+
31
35
  def self.reset
32
36
  @stubs = {}
33
37
  @default_stub = nil
@@ -4,6 +4,27 @@ require 'geocoder/results/base'
4
4
  module Geocoder::Result
5
5
  class BanDataGouvFr < Base
6
6
 
7
+ STATE_CODE_MAPPINGS = {
8
+ "Guadeloupe" => "01",
9
+ "Martinique" => "02",
10
+ "Guyane" => "03",
11
+ "La Réunion" => "04",
12
+ "Mayotte" => "06",
13
+ "Île-de-France" => "11",
14
+ "Centre-Val de Loire" => "24",
15
+ "Bourgogne-Franche-Comté" => "27",
16
+ "Normandie" => "28",
17
+ "Hauts-de-France" => "32",
18
+ "Grand Est" => "44",
19
+ "Pays de la Loire" => "52",
20
+ "Bretagne" => "53",
21
+ "Nouvelle-Aquitaine" => "75",
22
+ "Occitanie" => "76",
23
+ "Auvergne-Rhône-Alpes" => "84",
24
+ "Provence-Alpes-Côte d'Azur" => "93",
25
+ "Corse" => "94"
26
+ }.freeze
27
+
7
28
  #### BASE METHODS ####
8
29
 
9
30
  def self.response_attributes
@@ -209,6 +230,10 @@ module Geocoder::Result
209
230
  end
210
231
  end
211
232
 
233
+ def region_code
234
+ STATE_CODE_MAPPINGS[region_name]
235
+ end
236
+
212
237
  def country
213
238
  "France"
214
239
  end
@@ -235,7 +260,7 @@ module Geocoder::Result
235
260
  alias_method :street, :street_name
236
261
  alias_method :city, :city_name
237
262
  alias_method :state, :region_name
238
- alias_method :state_code, :state
263
+ alias_method :state_code, :region_code
239
264
 
240
265
  #### CITIES' METHODS ####
241
266
 
@@ -9,6 +9,10 @@ module Geocoder::Result
9
9
  @data = flatten_hash(data)
10
10
  end
11
11
 
12
+ def coordinates
13
+ [@data['location_latitude'], @data['location_longitude']]
14
+ end
15
+
12
16
  def flatten_hash(hash)
13
17
  hash.each_with_object({}) do |(k, v), h|
14
18
  if v.is_a? Hash
@@ -35,14 +39,6 @@ module Geocoder::Result
35
39
  @data['location_country_code']
36
40
  end
37
41
 
38
- def latitude
39
- @data['location_latitude']
40
- end
41
-
42
- def longitude
43
- @data['location_longitude']
44
- end
45
-
46
42
  def postal_code
47
43
  @data['location_postal']
48
44
  end
@@ -8,7 +8,7 @@ module Geocoder::Result
8
8
  end
9
9
 
10
10
  def coordinates
11
- @data['centroide_ll'][6..-2].split(' ').map(&:to_f)
11
+ @data['centroide_ll'][6..-2].split(' ').map(&:to_f).reverse
12
12
  end
13
13
 
14
14
  def formatted_address
@@ -1,3 +1,3 @@
1
1
  module Geocoder
2
- VERSION = "1.6.4"
2
+ VERSION = "1.6.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geocoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.4
4
+ version: 1.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Reisner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-06 00:00:00.000000000 Z
11
+ date: 2021-02-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Object geocoding (by street or IP address), reverse geocoding (coordinates
14
14
  to street address), distance queries for ActiveRecord and Mongoid, result caching,