countries 4.2.3 → 5.0.0

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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/codeql-analysis.yml +70 -0
  3. data/.github/workflows/tests.yml +1 -5
  4. data/.rubocop.yml +40 -1
  5. data/.rubocop_todo.yml +8 -41
  6. data/CHANGELOG.md +7 -2
  7. data/Gemfile +5 -3
  8. data/README.markdown +22 -5
  9. data/Rakefile +13 -31
  10. data/bin/console +1 -0
  11. data/countries.gemspec +7 -5
  12. data/lib/countries/cache/countries.json +1 -1
  13. data/lib/countries/configuration.rb +2 -0
  14. data/lib/countries/country/class_methods.rb +12 -97
  15. data/lib/countries/country/currency_methods.rb +2 -0
  16. data/lib/countries/country/emoji.rb +2 -3
  17. data/lib/countries/country/finder_methods.rb +81 -0
  18. data/lib/countries/country.rb +3 -40
  19. data/lib/countries/data/countries/KN.yaml +0 -1
  20. data/lib/countries/data.rb +34 -37
  21. data/lib/countries/global.rb +2 -0
  22. data/lib/countries/iso3166.rb +3 -0
  23. data/lib/countries/kwarg_struct.rb +2 -0
  24. data/lib/countries/mongoid.rb +2 -0
  25. data/lib/countries/sources/cldr/downloader.rb +8 -8
  26. data/lib/countries/sources/cldr/subdivision.rb +3 -0
  27. data/lib/countries/sources/cldr/subdivision_updater.rb +23 -17
  28. data/lib/countries/sources/local/cached_loader.rb +3 -0
  29. data/lib/countries/sources/local/subdivision.rb +5 -2
  30. data/lib/countries/sources.rb +2 -0
  31. data/lib/countries/structure.rb +1 -1
  32. data/lib/countries/subdivision.rb +2 -0
  33. data/lib/countries/tasks/geocoding.rake +15 -6
  34. data/lib/countries/tasks/postal_codes.rake +5 -3
  35. data/lib/countries/timezones.rb +5 -2
  36. data/lib/countries/translations.rb +2 -0
  37. data/lib/countries/version.rb +3 -1
  38. data/lib/countries.rb +2 -0
  39. data/spec/00_global_spec.rb +2 -0
  40. data/spec/configuration_spec.rb +11 -5
  41. data/spec/country_spec.rb +71 -22
  42. data/spec/data_spec.rb +24 -18
  43. data/spec/mongoid_spec.rb +2 -2
  44. data/spec/perf_spec.rb +16 -16
  45. data/spec/spec_helper.rb +2 -0
  46. data/spec/subdivision_spec.rb +6 -4
  47. data/spec/thread_safety_spec.rb +4 -3
  48. data/spec/timezone_spec.rb +2 -0
  49. metadata +14 -12
  50. 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: a8a95786ec6321b9d8d1f9b11854cd37d693554a2052a270187a7ee82f8d629b
4
+ data.tar.gz: 9c360efbd86c1f91526ec28474041255c54d81585c689c8dd1b492c33e7db060
5
5
  SHA512:
6
- metadata.gz: f1a25098d98189de1f4b74374871559cc78ed42aba67166043d0f9892c8d91a2a8e27c6ab410f26e80a5a02e6bfe79194c4310b3b6e5f7ae0dec61869fdd2ca2
7
- data.tar.gz: 3d51bbb186fdda7cc2172d5779d4b4be107ad1295a099894ab8d7f8c6a5b0601a38a03bc8494e017a2234ab081b5b234df913ee94512a6e59d281685c12a09d4
6
+ metadata.gz: 077e94f77953b21e4d3e59e7830429f9effa3633e310ce682d554f3eeefdf976fc0290a6d1ae9e1ee5f379f3f7abbb8043a1484822ea82473f833f3369b8f9f0
7
+ data.tar.gz: 7fcdbfc5e27c1eb44e684694da9974000f7d076da9770138c9402ec46866cdd7e52c90141c815559149b7a5fe6e00ee16a2578c6b6f966c5d7bcc5c819840255
@@ -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
19
- bundler-version: default
20
- - ruby-version: 2.6.9
21
- bundler-version: default
22
18
  - ruby-version: 2.7.5
23
19
  bundler-version: default
24
20
  - ruby-version: 3.0.3
25
21
  bundler-version: default
26
- - ruby-version: 3.1.0
22
+ - ruby-version: 3.1.1
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,17 @@
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.0] (https://github.com/countries/countries/releases/tag/v5.0.') (2022/04/03 17:44 +00:00)
7
7
 
8
8
  **Breaking Changes**
9
9
 
10
- - Drop support for Ruby 2.5 and 2.6 [\#708](https://github.com/countries/countries/pull/708) ([pmor](https://github.com/pmor))
10
+ - Drop support for Ruby 2.5 and 2.6. (EOL in 2021-03-31 and 2022-03-31, respectively)
11
+ - Remove deprecated attributes and add new `#find_by_any_name` finder, see https://github.com/countries/countries#upgrading-to-42-and-5x for details
12
+
13
+ **Merged pull requests:**
11
14
 
15
+ - Drop support for Ruby 2.5 and 2.6 [\#708](https://github.com/countries/countries/pull/708) ([pmor](https://github.com/pmor))
16
+ - Remove deprecated attributes; Add new `#find_by_any_name` finder [\#745](https://github.com/countries/countries/pull/708) ([pmor](https://github.com/pmor))
12
17
 
13
18
  ## [4.2.3](https://github.com/countries/countries/releases/tag/v4.2.2) (2022/03/24 11:00 +00:00)
14
19
 
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
 
@@ -52,10 +54,25 @@ In release 4.2 the `#name` attribute was deprecated in favour of `#iso_short_nam
52
54
 
53
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.
54
56
 
55
- 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`
56
71
 
57
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.
58
73
 
74
+ The 5.0 release removed support for Ruby 2.5 (EOL 2021-03-01) and 2.6 (EOL 2022-03-31)
75
+
59
76
  ## Selective Loading of Locales
60
77
 
61
78
  As of 2.0 you can selectively load locales to reduce memory usage in production.
@@ -82,7 +99,8 @@ end
82
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:
83
100
 
84
101
  ```ruby
85
- 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')
86
104
  h = ISO3166::Country.find_all_by(:translated_names, 'França')
87
105
  list = ISO3166::Country.find_all_countries_by_region('Americas')
88
106
  c = ISO3166::Country.find_country_by_alpha3('can')
@@ -91,8 +109,7 @@ c = ISO3166::Country.find_country_by_alpha3('can')
91
109
  For a list of available attributes please see `ISO3166::DEFAULT_COUNTRY_HASH`.
92
110
  Note: searches are *case insensitive and ignore accents*.
93
111
 
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
-
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_
96
113
 
97
114
  ## Country Info
98
115
 
@@ -149,7 +166,7 @@ c.region # => "Americas"
149
166
  c.subregion # => "Northern America"
150
167
  ```
151
168
 
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.
169
+ 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
170
 
154
171
  ### Timezones **(optional)**
155
172
 
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/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