countries 4.2.2 → 5.0.1

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.
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 +22 -4
  7. data/Gemfile +5 -3
  8. data/LICENSE +3 -1
  9. data/README.markdown +34 -15
  10. data/Rakefile +15 -31
  11. data/bin/console +1 -0
  12. data/countries.gemspec +8 -6
  13. data/lib/countries/cache/countries.json +1 -1
  14. data/lib/countries/cache/locales/oc.json +1 -1
  15. data/lib/countries/cache/locales/ti.json +1 -1
  16. data/lib/countries/cache/locales/zu.json +1 -1
  17. data/lib/countries/configuration.rb +2 -0
  18. data/lib/countries/country/class_methods.rb +12 -97
  19. data/lib/countries/country/currency_methods.rb +2 -0
  20. data/lib/countries/country/emoji.rb +2 -3
  21. data/lib/countries/country/finder_methods.rb +81 -0
  22. data/lib/countries/country.rb +3 -40
  23. data/lib/countries/data/countries/KN.yaml +0 -1
  24. data/lib/countries/data/subdivisions/PT.yaml +13 -13
  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 +16 -14
  55. data/lib/countries/setup.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5f2fb748d2a4450607d449b042b5e4b7ed07a53424a624ddd48a44a73aff087
4
- data.tar.gz: 6d95e456629c9116e35fb9fce029503f24bd199883c10eb77f5dc775702dac6c
3
+ metadata.gz: 3f4c18c20a21b358c31c0453a13252eb30f5b9aff3b2fc09803b83ab42bbc434
4
+ data.tar.gz: a7b7997ff12a290673f51e3b672dd501fb0f42e9a02c17a0c2c75c92a593be27
5
5
  SHA512:
6
- metadata.gz: 50fd92660600b1a2592457702e9e0068cc6a1268ab4d89f73a256b7acf23ef1e92c6f726986cb20c71d203dbc9c91d2fdc7dc80b2b193aa9728af3e90dd005e1
7
- data.tar.gz: 70ec6a17d80e78e6b5b7ee9bc45b8286218e0974bae3d0c01247e00ed3ba719cdc03c0d498ec77fb799d8e828b804febc722af56568a2146f5221fd9905b9e2b
6
+ metadata.gz: 23ffc95eb8c0584db74fc5cdebc3965020c5047784fc5e18b8a1064dc61e28a3962e4d32516fff593652ce8ae5c0fdfd05e3ac6389f975ca7777cc1f1399f978
7
+ data.tar.gz: 5a749c3c933871d1716102959bcbd6a96f0f5207317267a645cdbac1dddc4daff0e66701bc735c605ad0cf3a53b7c2e0f54564ae84bf504b0b1b9d45408190f9
@@ -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,19 +3,37 @@
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.1] (https://github.com/countries/countries/releases/tag/v5.0.1') (2022/05/02 12:03 +00:00)
7
+
8
+ **Merged pull requests:**
9
+
10
+ * Added subdivision_names_with_codes method in documentation [\#747](https://github.com/countries/countries/pull/747) ([arymoraes](https://github.com/arymoraes))
11
+ * Corrected Portuguese subdivision names by @FilipaDurao in [\#748](https://github.com/countries/countries/pull/748) ([FilipaDurao](https://github.com/FilipaDurao))
12
+
13
+ ## [5.0.0] (https://github.com/countries/countries/releases/tag/v5.0.0') (2022/04/03 17:44 +00:00)
7
14
 
8
15
  **Breaking Changes**
9
16
 
17
+ - Drop support for Ruby 2.5 and 2.6. (EOL in 2021-03-31 and 2022-03-31, respectively)
18
+ - Remove deprecated attributes and add new `#find_by_any_name` finder, see https://github.com/countries/countries#upgrading-to-42-and-5x for details
19
+
20
+ **Merged pull requests:**
21
+
10
22
  - Drop support for Ruby 2.5 and 2.6 [\#708](https://github.com/countries/countries/pull/708) ([pmor](https://github.com/pmor))
23
+ - Remove deprecated attributes; Add new `#find_by_any_name` finder [\#745](https://github.com/countries/countries/pull/708) ([pmor](https://github.com/pmor))
11
24
 
12
- ## [4.2.2](https://github.com/countries/countries/releases/tag/v4.2.2) (2022/02/17 13:52 +00:00)
25
+ ## [4.2.3](https://github.com/countries/countries/releases/tag/v4.2.2) (2022/03/24 11:00 +00:00)
26
+
27
+ **IMPORTANT NOTE: This will be be the last release of the 4.x series, and the last one to support Ruby 2.5 and 2.6**
13
28
 
14
- **IMPORTANT NOTE: This should be be the last release of the 4.x series, and the last one to support Ruby 2.5 and 2.6**
29
+ * Use bundle add instead [\#743](https://github.com/countries/countries/pull/743) ([glaucocustodio](https://github.com/glaucocustodio))
30
+ * update i18n_data [\#742](https://github.com/countries/countries/pull/742) ([bonekost](https://github.com/bonekost))
31
+
32
+ ## [4.2.2](https://github.com/countries/countries/releases/tag/v4.2.2) (2022/02/17 13:52 +00:00)
15
33
 
16
34
  **Merged pull requests:**
17
35
 
18
- * http:// -> https:// by [\#737](https://github.com/countries/countries/pull/737) ([biow0lf](https://github.com/biow0lf))
36
+ * http:// -> https:// [\#737](https://github.com/countries/countries/pull/737) ([biow0lf](https://github.com/biow0lf))
19
37
  * Update AE start_of_week to monday. [\#739](https://github.com/countries/countries/pull/739) ([pmor](https://github.com/pmor))
20
38
  * Fix Subdivision data by [\#740](https://github.com/countries/countries/pull/740) ([pmor](https://github.com/pmor))
21
39
 
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/LICENSE CHANGED
@@ -1,4 +1,6 @@
1
- Copyright (c) 2012 hexorx
1
+ Copyright (c) 2012-2015 hexorx
2
+ Copyright (c) 2015-2021 hexorx, rposborne
3
+ Copyright (c) 2022 hexorx, rposborne, pmor
2
4
 
3
5
  MIT License
4
6
 
data/README.markdown CHANGED
@@ -3,23 +3,21 @@
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
 
9
11
  ```bash
10
- gem install countries
11
- ```
12
+ gem install countries
13
+ ```
12
14
 
13
- Or you can install via Bundler if you are using Rails. Add this line to your application's Gemfile:
15
+ Or you can install via Bundler if you are using Rails:
14
16
 
15
- ```ruby
16
- gem 'countries'
17
+ ```bash
18
+ bundle add countries
17
19
  ```
18
20
 
19
- And then execute:
20
-
21
- $ bundle
22
-
23
21
  ## Basic Usage
24
22
 
25
23
  Simply load a new country object using Country.new(*alpha2*) or the shortcut Country[*alpha2*]. An example works best.
@@ -56,10 +54,25 @@ In release 4.2 the `#name` attribute was deprecated in favour of `#iso_short_nam
56
54
 
57
55
  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.
58
56
 
59
- The `#name` and `#names` attributes, and corresponding finder methods will be removed in 5.0.
57
+ The `#name` and `#names` attributes, and corresponding finder methods were removed in 5.0.
58
+
59
+ The replacement finders added in 5.0 are:
60
+
61
+ - `#find_by_name` => `#find_by_any_name` - Searches all the name attributes, same as before
62
+ - `#find_by_names` => `#find_by_unofficial_names`
63
+ - `#find_*_by_name` => `#find_*_by_any_name`
64
+ - `#find_*_by_names` => `#find_*_by_unofficial_names`
65
+
66
+ With the addition of the new name attributes, there are now also the following finders:
67
+
68
+ - `#find_by_common_name`/`#find_*_by_common_name`
69
+ - `#find_by_iso_short_name`/`#find_*_by_iso_short_name`
70
+ - `#find_by_iso_long_name`/`#find_*_by_iso_long_name`
60
71
 
61
72
  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.
62
73
 
74
+ The 5.0 release removed support for Ruby 2.5 (EOL 2021-03-01) and 2.6 (EOL 2022-03-31)
75
+
63
76
  ## Selective Loading of Locales
64
77
 
65
78
  As of 2.0 you can selectively load locales to reduce memory usage in production.
@@ -86,7 +99,8 @@ end
86
99
  You can lookup a country or an array of countries using any of the data attributes via the find\_country\_by_*attribute* dynamic methods:
87
100
 
88
101
  ```ruby
89
- c = ISO3166::Country.find_country_by_iso_short_name('united states')
102
+ c = ISO3166::Country.find_country_by_iso_short_name('italy')
103
+ c = ISO3166::Country.find_country_by_any_name('united states')
90
104
  h = ISO3166::Country.find_all_by(:translated_names, 'França')
91
105
  list = ISO3166::Country.find_all_countries_by_region('Americas')
92
106
  c = ISO3166::Country.find_country_by_alpha3('can')
@@ -95,8 +109,7 @@ c = ISO3166::Country.find_country_by_alpha3('can')
95
109
  For a list of available attributes please see `ISO3166::DEFAULT_COUNTRY_HASH`.
96
110
  Note: searches are *case insensitive and ignore accents*.
97
111
 
98
- _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_
99
-
112
+ _Please note that `find_by_name`, `find_by_names`, `find_*_by_name` and `find_*_by_names` methods were removed in 5.0. See [Upgrading to 4.2 and 5.x](#upgrading-to-4-2-and-5-x) above for the new methods_
100
113
 
101
114
  ## Country Info
102
115
 
@@ -140,6 +153,9 @@ c.nationality # => "American"
140
153
  ```ruby
141
154
  c.subdivisions # => {"CO" => {"name" => "Colorado", "names" => "Colorado"}, ... }
142
155
  c.states # => {"CO" => {"name" => "Colorado", "names" => "Colorado"}, ... }
156
+
157
+ # Get specific translations for the country subdivisions
158
+ c.subdivision_names_with_codes('es') #=> [ ..., ["Nuevo Hampshire", "NH"], ["Nueva Jersey", "NJ"], ... ]
143
159
  ```
144
160
 
145
161
  ### Location
@@ -153,7 +169,7 @@ c.region # => "Americas"
153
169
  c.subregion # => "Northern America"
154
170
  ```
155
171
 
156
- 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.
172
+ 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.
157
173
 
158
174
  ### Timezones **(optional)**
159
175
 
@@ -349,5 +365,8 @@ the next `rake update_cache`.
349
365
 
350
366
  ## Copyright
351
367
 
352
- Copyright (c) 2016 hexorx. See LICENSE for details.
368
+ Copyright (c) 2012-2015 hexorx
369
+ Copyright (c) 2015-2021 hexorx, rposborne
370
+ Copyright (c) 2022 hexorx, rposborne, pmor
353
371
 
372
+ 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,12 @@ 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]
43
+ # Ignore locales that have bad data in i18n_data 0.16.0
44
+ language_keys -= %w[AY AM BA]
40
45
  language_keys.each do |locale|
41
46
  locale = locale.downcase
42
47
  begin
@@ -46,40 +51,19 @@ task :update_cache do
46
51
  end
47
52
 
48
53
  # Apply any known corrections to i18n_data
49
- unless corrections[locale].nil?
50
- corrections[locale].each do |alpha2, localized_name|
51
- local_names[alpha2] = localized_name
52
- end
54
+ corrections[locale]&.each do |alpha2, localized_name|
55
+ local_names[alpha2] = localized_name
53
56
  end
54
57
 
55
- 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)
56
60
  end
57
61
 
58
62
  codes.each do |alpha2|
59
- 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]
60
65
  end
61
66
 
62
- 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)
63
69
  end
64
-
65
- # Temporary task to update YAML file structure with iso_long_name and iso_short_name attributes
66
- task :update_iso_names do
67
- require 'csv'
68
- isodata = CSV.read 'isonames.csv', headers: true
69
-
70
- d = Dir['lib/countries/data/countries/*.yaml']
71
- d.each do |file|
72
- puts "checking : #{file}"
73
- data = YAML.load_file(file)
74
-
75
- country_code = data.keys.first
76
- iso_country = isodata.find {|c| c['cc'] == country_code}
77
-
78
- data.values.first['iso_long_name'] = iso_country['iso_full_name']
79
- data.values.first['iso_short_name'] = data.values.first.delete('name')
80
-
81
- data[country_code.upcase] = data[country_code.upcase].sort.to_h
82
-
83
- File.open(file, 'w') { |f| f.write data.to_yaml }
84
- end
85
- end
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
- gem.add_dependency('i18n_data', '~> 0.15.0')
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