countries 4.2.3 → 5.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/codeql-analysis.yml +70 -0
  3. data/.github/workflows/tests.yml +3 -7
  4. data/.rubocop.yml +40 -1
  5. data/.rubocop_todo.yml +8 -41
  6. data/CHANGELOG.md +21 -2
  7. data/Gemfile +5 -3
  8. data/README.markdown +48 -60
  9. data/Rakefile +13 -31
  10. data/UPGRADE.md +26 -0
  11. data/bin/console +1 -0
  12. data/countries.gemspec +7 -5
  13. data/lib/countries/cache/countries.json +1 -1
  14. data/lib/countries/cache/locales/en.json +1 -1
  15. data/lib/countries/configuration.rb +2 -0
  16. data/lib/countries/country/class_methods.rb +12 -97
  17. data/lib/countries/country/currency_methods.rb +2 -0
  18. data/lib/countries/country/emoji.rb +2 -3
  19. data/lib/countries/country/finder_methods.rb +81 -0
  20. data/lib/countries/country.rb +3 -40
  21. data/lib/countries/data/countries/KN.yaml +0 -1
  22. data/lib/countries/data/subdivisions/MX.yaml +3 -15
  23. data/lib/countries/data/subdivisions/PT.yaml +13 -13
  24. data/lib/countries/data/translation_corrections.yaml +2 -0
  25. data/lib/countries/data.rb +34 -37
  26. data/lib/countries/global.rb +2 -0
  27. data/lib/countries/iso3166.rb +3 -0
  28. data/lib/countries/kwarg_struct.rb +2 -0
  29. data/lib/countries/mongoid.rb +2 -0
  30. data/lib/countries/sources/cldr/downloader.rb +8 -8
  31. data/lib/countries/sources/cldr/subdivision.rb +3 -0
  32. data/lib/countries/sources/cldr/subdivision_updater.rb +23 -17
  33. data/lib/countries/sources/local/cached_loader.rb +3 -0
  34. data/lib/countries/sources/local/subdivision.rb +5 -2
  35. data/lib/countries/sources.rb +2 -0
  36. data/lib/countries/structure.rb +1 -1
  37. data/lib/countries/subdivision.rb +2 -0
  38. data/lib/countries/tasks/geocoding.rake +15 -6
  39. data/lib/countries/tasks/postal_codes.rake +5 -3
  40. data/lib/countries/timezones.rb +5 -2
  41. data/lib/countries/translations.rb +2 -0
  42. data/lib/countries/version.rb +3 -1
  43. data/lib/countries.rb +2 -0
  44. data/spec/00_global_spec.rb +2 -0
  45. data/spec/configuration_spec.rb +11 -5
  46. data/spec/country_spec.rb +71 -22
  47. data/spec/data_spec.rb +24 -18
  48. data/spec/mongoid_spec.rb +2 -2
  49. data/spec/perf_spec.rb +16 -16
  50. data/spec/spec_helper.rb +2 -0
  51. data/spec/subdivision_spec.rb +6 -4
  52. data/spec/thread_safety_spec.rb +4 -3
  53. data/spec/timezone_spec.rb +2 -0
  54. metadata +15 -12
  55. data/lib/countries/setup.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d9b0ecf844c063dc4ce2deeeb02a9fb2832a0640b8ed232b8d2c40ff7061692
4
- data.tar.gz: 8969a80a3834eec68f5927dc14aa8470a62c438ec833c8c5a2183e632aabce59
3
+ metadata.gz: baeec795ef76c0171afb436d9371e30837e0eef7290642e36ae9ac96a99d02aa
4
+ data.tar.gz: e621054ef6fa804e1116a0ac79fbaf6251a32181bd4941c9028b9fcf0a9c6b19
5
5
  SHA512:
6
- metadata.gz: f1a25098d98189de1f4b74374871559cc78ed42aba67166043d0f9892c8d91a2a8e27c6ab410f26e80a5a02e6bfe79194c4310b3b6e5f7ae0dec61869fdd2ca2
7
- data.tar.gz: 3d51bbb186fdda7cc2172d5779d4b4be107ad1295a099894ab8d7f8c6a5b0601a38a03bc8494e017a2234ab081b5b234df913ee94512a6e59d281685c12a09d4
6
+ metadata.gz: 388d84578afe4d7c8fd5e31dbfa0827e0a1ed2f63aee0f4ebd59da436200268ffa23af28952351474c47bd51ac4d6bfe1ea798353987da9ec1e6e31dce1da2af
7
+ data.tar.gz: a610bd578f9ceba72e04353c1edb69d4f93b23ba4ad398f1280b86959b4d19ef079c30df102b715097755136b32926d3e5ffdd48176e032fd05047303390e84d
@@ -0,0 +1,70 @@
1
+ # For most projects, this workflow file will not need changing; you simply need
2
+ # to commit it to your repository.
3
+ #
4
+ # You may wish to alter this file to override the set of languages analyzed,
5
+ # or to provide custom queries or build logic.
6
+ #
7
+ # ******** NOTE ********
8
+ # We have attempted to detect the languages in your repository. Please check
9
+ # the `language` matrix defined below to confirm you have the correct set of
10
+ # supported CodeQL languages.
11
+ #
12
+ name: "CodeQL"
13
+
14
+ on:
15
+ push:
16
+ branches: [ master ]
17
+ pull_request:
18
+ # The branches below must be a subset of the branches above
19
+ branches: [ master ]
20
+ schedule:
21
+ - cron: '19 13 * * 5'
22
+
23
+ jobs:
24
+ analyze:
25
+ name: Analyze
26
+ runs-on: ubuntu-latest
27
+ permissions:
28
+ actions: read
29
+ contents: read
30
+ security-events: write
31
+
32
+ strategy:
33
+ fail-fast: false
34
+ matrix:
35
+ language: [ 'ruby' ]
36
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37
+ # Learn more about CodeQL language support at https://git.io/codeql-language-support
38
+
39
+ steps:
40
+ - name: Checkout repository
41
+ uses: actions/checkout@v3
42
+
43
+ # Initializes the CodeQL tools for scanning.
44
+ - name: Initialize CodeQL
45
+ uses: github/codeql-action/init@v1
46
+ with:
47
+ languages: ${{ matrix.language }}
48
+ # If you wish to specify custom queries, you can do so here or in a config file.
49
+ # By default, queries listed here will override any specified in a config file.
50
+ # Prefix the list here with "+" to use these queries and those in the config file.
51
+ # queries: ./path/to/local/query, your-org/your-repo/queries@main
52
+
53
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54
+ # If this step fails, then you should remove it and run the build manually (see below)
55
+ - name: Autobuild
56
+ uses: github/codeql-action/autobuild@v1
57
+
58
+ # ℹ️ Command-line programs to run using the OS shell.
59
+ # 📚 https://git.io/JvXDl
60
+
61
+ # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
62
+ # and modify them (or add more) to build your code if your project
63
+ # uses a compiled language
64
+
65
+ #- run: |
66
+ # make bootstrap
67
+ # make release
68
+
69
+ - name: Perform CodeQL Analysis
70
+ uses: github/codeql-action/analyze@v1
@@ -15,15 +15,11 @@ jobs:
15
15
  strategy:
16
16
  matrix:
17
17
  include:
18
- - ruby-version: 2.5.9
18
+ - ruby-version: 2.7.6
19
19
  bundler-version: default
20
- - ruby-version: 2.6.9
20
+ - ruby-version: 3.0.4
21
21
  bundler-version: default
22
- - ruby-version: 2.7.5
23
- bundler-version: default
24
- - ruby-version: 3.0.3
25
- bundler-version: default
26
- - ruby-version: 3.1.0
22
+ - ruby-version: 3.1.2
27
23
  bundler-version: default
28
24
  steps:
29
25
  - uses: actions/checkout@v2
data/.rubocop.yml CHANGED
@@ -1 +1,40 @@
1
- inherit_from: .rubocop_todo.yml
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ NewCops: enable
5
+
6
+ Layout/LineLength:
7
+ Exclude:
8
+ - countries.gemspec
9
+
10
+ Metrics/BlockLength:
11
+ Exclude:
12
+ - 'spec/**/*'
13
+ - Rakefile
14
+ - 'spec/**/*'
15
+ - 'lib/countries/tasks/*'
16
+
17
+ Style/RescueModifier:
18
+ Enabled: false
19
+
20
+ Style/CaseEquality:
21
+ Exclude:
22
+ - 'lib/countries/country/finder_methods.rb'
23
+
24
+ Style/IfUnlessModifier:
25
+ Exclude:
26
+ - 'spec/thread_safety_spec.rb'
27
+
28
+ Naming/MethodName:
29
+ Exclude:
30
+ - 'lib/countries/country/class_methods.rb'
31
+
32
+ Lint/AmbiguousBlockAssociation:
33
+ Exclude:
34
+ - 'spec/perf_spec.rb'
35
+
36
+ Metrics/MethodLength:
37
+ Max: 20
38
+
39
+ Metrics/ClassLength:
40
+ Max: 130
data/.rubocop_todo.yml CHANGED
@@ -1,52 +1,19 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2016-09-19 23:29:07 -0400 using RuboCop version 0.43.0.
3
+ # on 2022-01-07 11:03:11 UTC using RuboCop version 1.24.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
- # Offense count: 1
9
- # Configuration parameters: CountComments.
10
- Metrics/ClassLength:
11
- Max: 101
12
8
 
13
- # Offense count: 64
14
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
15
- # URISchemes: http, https
16
- Metrics/LineLength:
17
- Max: 483
18
9
 
19
- # Offense count: 1
10
+ # Offense count: 3
11
+ # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
20
12
  Metrics/AbcSize:
21
- Max: 19
13
+ Max: 33
22
14
 
23
- # Offense count: 1
24
- Style/CaseEquality:
25
- Exclude:
26
- - 'lib/countries/country/class_methods.rb'
27
-
28
- # Offense count: 7
29
- Style/ClassVars:
30
- Exclude:
31
- - 'lib/countries/data.rb'
32
-
33
- # Offense count: 9
15
+ # Enable after the doc branch is merged
34
16
  Style/Documentation:
35
- Exclude:
36
- - 'spec/**/*'
37
- - 'test/**/*'
38
- - 'lib/countries/configuration.rb'
39
- - 'lib/countries/country.rb'
40
- - 'lib/countries/country/class_methods.rb'
41
- - 'lib/countries/country/emoji.rb'
42
- - 'lib/countries/global.rb'
43
- - 'lib/countries/kwarg_struct.rb'
44
- - 'lib/countries/mongoid.rb'
45
-
46
-
47
- # Offense count: 1
48
- # Configuration parameters: EnforcedStyle, SupportedStyles.
49
- # SupportedStyles: snake_case, camelCase
50
- Style/MethodName:
51
- Exclude:
52
- - 'lib/countries/country/class_methods.rb'
17
+ Enabled: false
18
+ # Exclude:
19
+ # - 'spec/**/*'
data/CHANGELOG.md CHANGED
@@ -3,12 +3,31 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project adheres to [Semantic Versioning](https://semver.org/).
5
5
 
6
- ## [Future 5.0 release]
6
+ ## [5.0.2](https://github.com/countries/countries/releases/tag/v5.0.2') (2022/06/02 20:01 +00:00)
7
+
8
+ **Merged pull requests:**
9
+
10
+ * Fix common name for IR [\#754](https://github.com/countries/countries/pull/754) ([pmor](https://github.com/pmor))
11
+ * Update MX subdivisions: Remove DIF and update some unofficial names [\#755](https://github.com/countries/countries/pull/755) ([pmor](https://github.com/pmor))
12
+
13
+ ## [5.0.1](https://github.com/countries/countries/releases/tag/v5.0.1') (2022/05/02 12:03 +00:00)
14
+
15
+ **Merged pull requests:**
16
+
17
+ * Added subdivision_names_with_codes method in documentation [\#747](https://github.com/countries/countries/pull/747) ([arymoraes](https://github.com/arymoraes))
18
+ * Corrected Portuguese subdivision names [\#748](https://github.com/countries/countries/pull/748) ([FilipaDurao](https://github.com/FilipaDurao))
19
+
20
+ ## [5.0.0](https://github.com/countries/countries/releases/tag/v5.0.0') (2022/04/03 17:44 +00:00)
7
21
 
8
22
  **Breaking Changes**
9
23
 
10
- - Drop support for Ruby 2.5 and 2.6 [\#708](https://github.com/countries/countries/pull/708) ([pmor](https://github.com/pmor))
24
+ - Drop support for Ruby 2.5 and 2.6. (EOL in 2021-03-31 and 2022-03-31, respectively)
25
+ - Remove deprecated attributes and add new `#find_by_any_name` finder, see https://github.com/countries/countries#upgrading-to-42-and-5x for details
11
26
 
27
+ **Merged pull requests:**
28
+
29
+ - Drop support for Ruby 2.5 and 2.6 [\#708](https://github.com/countries/countries/pull/708) ([pmor](https://github.com/pmor))
30
+ - Remove deprecated attributes; Add new `#find_by_any_name` finder [\#745](https://github.com/countries/countries/pull/708) ([pmor](https://github.com/pmor))
12
31
 
13
32
  ## [4.2.3](https://github.com/countries/countries/releases/tag/v4.2.2) (2022/03/24 11:00 +00:00)
14
33
 
data/Gemfile CHANGED
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
- gem 'rake'
3
4
  gem 'geocoder'
5
+ gem 'money'
6
+ gem 'rake'
4
7
  gem 'retryable'
5
8
  gem 'tzinfo'
6
- gem 'money'
7
9
 
8
10
  # Specify your gem's dependencies in countries.gemspec
9
11
  gemspec
@@ -11,4 +13,4 @@ gemspec
11
13
  group :development, :test do
12
14
  gem 'pry'
13
15
  gem 'yaml'
14
- end
16
+ end
data/README.markdown CHANGED
@@ -3,6 +3,8 @@
3
3
  Countries is a collection of all sorts of useful information for every country in the ISO 3166 standard. It contains info for the following standards ISO3166-1 (countries), ISO3166-2 (states/subdivisions), ISO4217 (currency) and E.164 (phone numbers). I will add any country based data I can get access to. I hope this to be a repository for all country based information.
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/countries.svg)](https://badge.fury.io/rb/countries) [![Tests](https://github.com/countries/countries/actions/workflows/tests.yml/badge.svg)](https://github.com/countries/countries/actions/workflows/tests.yml) [![Code Climate](https://codeclimate.com/github/countries/countries.svg)](https://codeclimate.com/github/countries/countries)
6
+ [![CodeQL](https://github.com/countries/countries/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/countries/countries/actions/workflows/codeql-analysis.yml)
7
+
6
8
 
7
9
  ## Installation
8
10
 
@@ -46,53 +48,28 @@ gem 'countries', require: 'countries/global'
46
48
 
47
49
  ## Upgrading to 4.2 and 5.x
48
50
 
49
- In release 4.2 the `#name` attribute was deprecated in favour of `#iso_short_name` and we added the `#iso_long_name` attribute, to make it clear that these attributes use the ISO3166 names, and are not the "common names" most people might expect, eg: The ISO name for "United Kingdom" is "United Kingdom of Great Britain and Northern Ireland", but if you're building a dropdown box to select a country, you're likely expecting to see "United Kingdom" instead.
50
-
51
- "Common names" in English have been available in the translation data, via `#translation('en')`. As of release 4.2, a shortcut method has been added for simplicity, `#common_name`, which delegates to `#translation('en')`.
52
-
53
- For additional clarity, the `#names` method, which was an alias to `#unofficial_names` has also been deprecated, together with the finder methods that use `name` or `names` attributes.
51
+ Release 4.2.0 introduced changes to name attributes and finders and deprecated several methods to resolve some existing confusion regardign official ISO country names vs. the "common names" that are commonly used.
54
52
 
55
- The `#name` and `#names` attributes, and corresponding finder methods will be removed in 5.0.
53
+ The 5.0 release removed these deprecated methods and also removed support for Ruby 2.5 and 2.6
56
54
 
57
- For translated country names, we use data from [pkg-isocodes](https://salsa.debian.org/iso-codes-team/iso-codes), via the [i18n_data](https://github.com/grosser/i18n_data) gem, and these generally correspond to the expected "common names". These names and the corresponding methods have not been changed.
58
-
59
- ## Selective Loading of Locales
60
-
61
- As of 2.0 you can selectively load locales to reduce memory usage in production.
62
-
63
- By default we load `I18n.available_locales` if I18n is present, otherwise only `[:en]`. This means almost any Rails environment will only bring in its supported translations.
64
-
65
- You can add all the locales like this.
66
-
67
- ```ruby
68
- ISO3166.configure do |config|
69
- config.locales = [:af, :am, :ar, :as, :az, :be, :bg, :bn, :br, :bs, :ca, :cs, :cy, :da, :de, :dz, :el, :en, :eo, :es, :et, :eu, :fa, :fi, :fo, :fr, :ga, :gl, :gu, :he, :hi, :hr, :hu, :hy, :ia, :id, :is, :it, :ja, :ka, :kk, :km, :kn, :ko, :ku, :lt, :lv, :mi, :mk, :ml, :mn, :mr, :ms, :mt, :nb, :ne, :nl, :nn, :oc, :or, :pa, :pl, :ps, :pt, :ro, :ru, :rw, :si, :sk, :sl, :so, :sq, :sr, :sv, :sw, :ta, :te, :th, :ti, :tk, :tl, :tr, :tt, :ug, :uk, :ve, :vi, :wa, :wo, :xh, :zh, :zu]
70
- end
71
- ```
72
-
73
- or something a bit more simple
74
- ```ruby
75
- ISO3166.configure do |config|
76
- config.locales = [:en, :de, :fr, :es]
77
- end
78
- ```
55
+ Plase see [UPGRADE.md](../master/UPGRADE.md) for more information
79
56
 
80
57
  ## Attribute-Based Finder Methods
81
58
 
82
59
  You can lookup a country or an array of countries using any of the data attributes via the find\_country\_by_*attribute* dynamic methods:
83
60
 
84
61
  ```ruby
85
- c = ISO3166::Country.find_country_by_iso_short_name('united states')
62
+ c = ISO3166::Country.find_country_by_iso_short_name('italy')
63
+ c = ISO3166::Country.find_country_by_any_name('united states')
86
64
  h = ISO3166::Country.find_all_by(:translated_names, 'França')
87
65
  list = ISO3166::Country.find_all_countries_by_region('Americas')
88
- c = ISO3166::Country.find_country_by_alpha3('can')
66
+ c = ISO3166::Country.find_country_by_alpha2("FR")
89
67
  ```
90
68
 
91
69
  For a list of available attributes please see `ISO3166::DEFAULT_COUNTRY_HASH`.
92
70
  Note: searches are *case insensitive and ignore accents*.
93
71
 
94
- _Please note that `find_by_name`, `find_by_names`, `find_*_by_name` and `find_*_by_names` methods are deprecated and will be removed in 5.0. See [Upgrading to 4.2 and 5.x](#upgrading-to-4-2-and-5-x) above_
95
-
72
+ _Please note that `find_by_name`, `find_by_names`, `find_*_by_name` and `find_*_by_names` methods were removed in 5.0. See [UPGRADE.md](../blob/master/UPGRADE.md) for more information_
96
73
 
97
74
  ## Country Info
98
75
 
@@ -136,6 +113,9 @@ c.nationality # => "American"
136
113
  ```ruby
137
114
  c.subdivisions # => {"CO" => {"name" => "Colorado", "names" => "Colorado"}, ... }
138
115
  c.states # => {"CO" => {"name" => "Colorado", "names" => "Colorado"}, ... }
116
+
117
+ # Get specific translations for the country subdivisions
118
+ c.subdivision_names_with_codes('es') #=> [ ..., ["Nuevo Hampshire", "NH"], ["Nueva Jersey", "NJ"], ... ]
139
119
  ```
140
120
 
141
121
  ### Location
@@ -149,7 +129,7 @@ c.region # => "Americas"
149
129
  c.subregion # => "Northern America"
150
130
  ```
151
131
 
152
- Please note that `latitude_dec` and `longitude_dec` was be deprecated on release 4.2 and will be deleted in 5.0. These attributes have been redundant for several years, since the `latitude` and `longitude` fields have been switched decimal coordinates.
132
+ Please note that `latitude_dec` and `longitude_dec` were deprecated on release 4.2 and removed in 5.0. These attributes have been redundant for several years, since the `latitude` and `longitude` fields have been switched decimal coordinates.
153
133
 
154
134
  ### Timezones **(optional)**
155
135
 
@@ -198,13 +178,19 @@ c.in_eu? # => false
198
178
  c.in_eea? # => false
199
179
  ```
200
180
 
201
-
202
181
  ### European Single Market Membership
203
182
 
204
183
  ```ruby
205
184
  c.in_esm? # => false
206
185
  ```
207
186
 
187
+ ## Country Code in Emoji
188
+
189
+ ```ruby
190
+ c = Country['MY']
191
+ c.emoji_flag # => "🇲🇾"
192
+ ```
193
+
208
194
  ### Plucking multiple attributes
209
195
 
210
196
  ```ruby
@@ -242,6 +228,27 @@ A template for formatting addresses is available through the address_format meth
242
228
  c.address_format # => "{{recipient}}\n{{street}}\n{{city}} {{region}} {{postalcode}}\n{{country}}"
243
229
  ```
244
230
 
231
+ ## Selective Loading of Locales
232
+
233
+ As of 2.0 you can selectively load locales to reduce memory usage in production.
234
+
235
+ By default we load `I18n.available_locales` if I18n is present, otherwise only `[:en]`. This means almost any Rails environment will only bring in its supported translations.
236
+
237
+ You can add all the locales like this.
238
+
239
+ ```ruby
240
+ ISO3166.configure do |config|
241
+ config.locales = [:af, :am, :ar, :as, :az, :be, :bg, :bn, :br, :bs, :ca, :cs, :cy, :da, :de, :dz, :el, :en, :eo, :es, :et, :eu, :fa, :fi, :fo, :fr, :ga, :gl, :gu, :he, :hi, :hr, :hu, :hy, :ia, :id, :is, :it, :ja, :ka, :kk, :km, :kn, :ko, :ku, :lt, :lv, :mi, :mk, :ml, :mn, :mr, :ms, :mt, :nb, :ne, :nl, :nn, :oc, :or, :pa, :pl, :ps, :pt, :ro, :ru, :rw, :si, :sk, :sl, :so, :sq, :sr, :sv, :sw, :ta, :te, :th, :ti, :tk, :tl, :tr, :tt, :ug, :uk, :ve, :vi, :wa, :wo, :xh, :zh, :zu]
242
+ end
243
+ ```
244
+
245
+ or something a bit more simple
246
+ ```ruby
247
+ ISO3166.configure do |config|
248
+ config.locales = [:en, :de, :fr, :es]
249
+ end
250
+ ```
251
+
245
252
  ## Loading Custom Data
246
253
 
247
254
  As of 2.0 countries supports loading custom countries / overriding data in its data set, though if you choose to do this please contribute back to the upstream repo!
@@ -307,32 +314,14 @@ def country
307
314
  end
308
315
  ```
309
316
 
310
- ## Country Code in Emoji
311
-
312
- ```ruby
313
- c = Country['MY']
314
- c.emoji_flag # => "🇲🇾"
315
- ```
316
-
317
317
  ## Note on Patches/Pull Requests
318
318
 
319
- ### Please do not submit pull requests on `cache/**/*`
319
+ **Please do not submit pull requests on `cache/**/*`**. These files generated by a rake task when preparing new releases and are not meant to be manually updated.
320
320
 
321
- Any additions should be directed upstream to [pkg-isocodes](https://salsa.debian.org/iso-codes-team/iso-codes)
322
-
323
- Localized country name data is sourced from https://github.com/grosser/i18n_data (which is based on https://salsa.debian.org/iso-codes-team/iso-codes/). Issues regarding localized country names can be reported to https://github.com/grosser/i18n_data/issues or https://salsa.debian.org/iso-codes-team/iso-codes/issues
324
- If you need to correct an upstream translation please add it to the lib/countries/data/translations_corrections.yaml
325
-
326
- ```
327
- # Ex:
328
- #
329
- # locale:
330
- # alpha2: localized_name
331
- #
332
- ```
321
+ Localized country name data is sourced from the [i18n_data](https://github.com/grosser/i18n_data) gem (which is based on [pkg-isocodes](https://salsa.debian.org/iso-codes-team/iso-codes)).
322
+ Issues regarding localized country names can be reported to https://github.com/grosser/i18n_data/issues or https://salsa.debian.org/iso-codes-team/iso-codes/issues
333
323
 
334
- Any corrections can be applied in translations_corrections.yaml these will be injected during
335
- the next `rake update_cache`.
324
+ If you need to correct an upstream translation please add it to the `lib/countries/data/translations_corrections.yaml`, and they will be injected during the next `rake update_cache`.
336
325
 
337
326
  * Fork the project.
338
327
  * Make your feature addition or bug fix.
@@ -341,12 +330,11 @@ the next `rake update_cache`.
341
330
  * Commit, do not mess with rakefile, version, or history.
342
331
  (if you want to have your own version, that is fine but
343
332
  bump version in a commit by itself I can ignore when I pull)
344
- * Send me a pull request. Bonus points for topic branches.
333
+ * Make sure your you haven't made changes to `cache/**/*`
334
+ * Submit a pull request. Bonus points for topic branches.
345
335
 
346
336
  ## Copyright
347
337
 
348
- Copyright (c) 2012-2015 hexorx
349
- Copyright (c) 2015-2021 hexorx, rposborne
350
- Copyright (c) 2022 hexorx, rposborne, pmor
338
+ Copyright (c) 2012-2015 hexorx; 2015-2021 hexorx, rposborne; 2022 hexorx, rposborne, pmor
351
339
 
352
340
  See LICENSE for details.
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env rake
2
+ # frozen_string_literal: true
3
+
2
4
  require 'bundler/gem_tasks'
3
5
 
4
6
  require 'rake'
@@ -34,9 +36,10 @@ task :update_cache do
34
36
  codes = Dir['lib/countries/data/countries/*.yaml'].map { |x| File.basename(x, File.extname(x)) }.uniq.sort
35
37
  data = {}
36
38
 
37
- corrections = YAML.load_file(File.join(File.dirname(__FILE__), 'lib', 'countries', 'data', 'translation_corrections.yaml')) || {}
39
+ corrections_file = File.join(File.dirname(__FILE__), 'lib', 'countries', 'data', 'translation_corrections.yaml')
40
+ corrections = YAML.load_file(corrections_file) || {}
38
41
 
39
- language_keys = I18nData.languages.keys + ['zh_CN', 'zh_TW', 'zh_HK','bn_IN','pt_BR']
42
+ language_keys = I18nData.languages.keys + %w[zh_CN zh_TW zh_HK bn_IN pt_BR]
40
43
  # Ignore locales that have bad data in i18n_data 0.16.0
41
44
  language_keys -= %w[AY AM BA]
42
45
  language_keys.each do |locale|
@@ -48,40 +51,19 @@ task :update_cache do
48
51
  end
49
52
 
50
53
  # Apply any known corrections to i18n_data
51
- unless corrections[locale].nil?
52
- corrections[locale].each do |alpha2, localized_name|
53
- local_names[alpha2] = localized_name
54
- end
54
+ corrections[locale]&.each do |alpha2, localized_name|
55
+ local_names[alpha2] = localized_name
55
56
  end
56
57
 
57
- File.open(File.join(File.dirname(__FILE__), 'lib', 'countries', 'cache', 'locales', "#{locale.gsub(/_/, '-')}.json"), 'wb') { |f| f.write(local_names.to_json) }
58
+ out = File.join(File.dirname(__FILE__), 'lib', 'countries', 'cache', 'locales', "#{locale.gsub(/_/, '-')}.json")
59
+ File.binwrite(out, local_names.to_json)
58
60
  end
59
61
 
60
62
  codes.each do |alpha2|
61
- data[alpha2] ||= YAML.load_file(File.join(File.dirname(__FILE__), 'lib', 'countries', 'data', 'countries', "#{alpha2}.yaml"))[alpha2]
63
+ country_file = File.join(File.dirname(__FILE__), 'lib', 'countries', 'data', 'countries', "#{alpha2}.yaml")
64
+ data[alpha2] ||= YAML.load_file(country_file)[alpha2]
62
65
  end
63
66
 
64
- File.open(File.join(File.dirname(__FILE__), 'lib', 'countries', 'cache', 'countries.json'), 'wb') { |f| f.write(data.to_json) }
67
+ out_file = File.join(File.dirname(__FILE__), 'lib', 'countries', 'cache', 'countries.json')
68
+ File.binwrite(out_file, data.to_json)
65
69
  end
66
-
67
- # Temporary task to update YAML file structure with iso_long_name and iso_short_name attributes
68
- task :update_iso_names do
69
- require 'csv'
70
- isodata = CSV.read 'isonames.csv', headers: true
71
-
72
- d = Dir['lib/countries/data/countries/*.yaml']
73
- d.each do |file|
74
- puts "checking : #{file}"
75
- data = YAML.load_file(file)
76
-
77
- country_code = data.keys.first
78
- iso_country = isodata.find {|c| c['cc'] == country_code}
79
-
80
- data.values.first['iso_long_name'] = iso_country['iso_full_name']
81
- data.values.first['iso_short_name'] = data.values.first.delete('name')
82
-
83
- data[country_code.upcase] = data[country_code.upcase].sort.to_h
84
-
85
- File.open(file, 'w') { |f| f.write data.to_yaml }
86
- end
87
- end
data/UPGRADE.md ADDED
@@ -0,0 +1,26 @@
1
+ # Upgrading to 4.2 and 5.x
2
+
3
+ In release 4.2 the `#name` attribute was deprecated in favour of `#iso_short_name` and we added the `#iso_long_name` attribute, to make it clear that these attributes use the ISO3166 names, and are not the "common names" most people might expect, eg: The ISO name for "United Kingdom" is "United Kingdom of Great Britain and Northern Ireland", but if you're building a dropdown box to select a country, you're likely expecting to see "United Kingdom" instead.
4
+
5
+ "Common names" in English have been available in the translation data, via `#translation('en')`. As of release 4.2, a shortcut method has been added for simplicity, `#common_name`, which delegates to `#translation('en')`.
6
+
7
+ For additional clarity, the `#names` method, which was an alias to `#unofficial_names` has also been deprecated, together with the finder methods that use `name` or `names` attributes.
8
+
9
+ The `#name` and `#names` attributes, and corresponding finder methods were removed in 5.0.
10
+
11
+ The replacement finders added in 5.0 are:
12
+
13
+ - `#find_by_name` => `#find_by_any_name` - Searches all the name attributes, same as before
14
+ - `#find_by_names` => `#find_by_unofficial_names`
15
+ - `#find_*_by_name` => `#find_*_by_any_name`
16
+ - `#find_*_by_names` => `#find_*_by_unofficial_names`
17
+
18
+ With the addition of the new name attributes, there are now also the following finders:
19
+
20
+ - `#find_by_common_name`/`#find_*_by_common_name`
21
+ - `#find_by_iso_short_name`/`#find_*_by_iso_short_name`
22
+ - `#find_by_iso_long_name`/`#find_*_by_iso_long_name`
23
+
24
+ For translated country names, we use data from [pkg-isocodes](https://salsa.debian.org/iso-codes-team/iso-codes), via the [i18n_data](https://github.com/grosser/i18n_data) gem, and these generally correspond to the expected "common names". These names and the corresponding methods have not been changed.
25
+
26
+ The 5.0 release removed support for Ruby 2.5 (EOL 2021-03-01) and 2.6 (EOL 2022-03-31)
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'countries'
data/countries.gemspec CHANGED
@@ -1,5 +1,6 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/countries/version', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('lib/countries/version', __dir__)
3
4
 
4
5
  Gem::Specification.new do |gem|
5
6
  gem.authors = ['Josh Robinson', 'Joe Corcoran', 'Russell Osborne', 'Pedro Moreira']
@@ -10,7 +11,8 @@ Gem::Specification.new do |gem|
10
11
  gem.metadata = { 'bug_tracker_uri' => 'https://github.com/countries/countries/issues',
11
12
  'changelog_uri' => 'https://github.com/countries/countries/blob/master/CHANGELOG.md',
12
13
  'source_code_uri' => 'https://github.com/countries/countries',
13
- 'wiki_uri' => 'https://github.com/countries/countries/wiki'}
14
+ 'wiki_uri' => 'https://github.com/countries/countries/wiki',
15
+ 'rubygems_mfa_required' => 'true' }
14
16
 
15
17
  gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
16
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
@@ -19,11 +21,11 @@ Gem::Specification.new do |gem|
19
21
  gem.version = Countries::VERSION.dup
20
22
  gem.license = 'MIT'
21
23
 
22
- gem.required_ruby_version = '>= 2.5'
24
+ gem.required_ruby_version = '>= 2.7'
23
25
 
24
26
  gem.add_dependency('i18n_data', '~> 0.16.0')
25
27
  gem.add_dependency('sixarm_ruby_unaccent', '~> 1.1')
26
- gem.add_development_dependency('rspec', '>= 3')
27
28
  gem.add_development_dependency('activesupport', '>= 3')
28
29
  gem.add_development_dependency('nokogiri', '>= 1.8')
30
+ gem.add_development_dependency('rspec', '>= 3')
29
31
  end