countries 4.2.3 → 5.0.2

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 +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
data/spec/country_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
4
  NUM_OF_COUNTRIES = 249
@@ -48,7 +48,9 @@ describe ISO3166::Country do
48
48
  end
49
49
 
50
50
  it 'should return alternate names' do
51
- expect(country.unofficial_names).to eq(['United States', 'USA', 'Murica', 'Vereinigte Staaten von Amerika', 'États-Unis', 'Estados Unidos', 'アメリカ合衆国', 'Verenigde Staten'])
51
+ expect(country.unofficial_names).to eq(['United States', 'USA', 'Murica',
52
+ 'Vereinigte Staaten von Amerika', 'États-Unis',
53
+ 'Estados Unidos', 'アメリカ合衆国', 'Verenigde Staten'])
52
54
  end
53
55
 
54
56
  it 'should return translations' do
@@ -85,7 +87,7 @@ describe ISO3166::Country do
85
87
  expect(country.postal_code_format).to_not be_nil
86
88
 
87
89
  regex = Regexp.new(country.postal_code_format)
88
- expect(regex).to match("12345-6789")
90
+ expect(regex).to match('12345-6789')
89
91
 
90
92
  antarctica = ISO3166::Country.search('AQ')
91
93
  expect(antarctica.postal_code_format).to be_nil
@@ -123,7 +125,7 @@ describe ISO3166::Country do
123
125
  let(:country) { ISO3166::Country.search('BE') }
124
126
 
125
127
  it 'should return its local names based on its languages' do
126
- expect(country.local_names).to match_array(%w(België Belgique Belgien))
128
+ expect(country.local_names).to match_array(%w[België Belgique Belgien])
127
129
  end
128
130
 
129
131
  it 'should return its first local name' do
@@ -259,7 +261,7 @@ describe ISO3166::Country do
259
261
  end
260
262
 
261
263
  it 'should return an alphabetized list of subdivision names translated to current locale with codes' do
262
- ISO3166.configuration.locales = [:es, :de, :en]
264
+ ISO3166.configuration.locales = %i[es de en]
263
265
 
264
266
  subdivisions = ISO3166::Country.search('EG').subdivision_names_with_codes(:es)
265
267
  expect(subdivisions).to be_an(Array)
@@ -371,11 +373,11 @@ describe ISO3166::Country do
371
373
  expect(countries.first[0]).to be_a(String)
372
374
  expect(countries.first[0]).to eq('Afghanistan')
373
375
  expect(countries.size).to eq(NUM_OF_COUNTRIES)
374
- expect(countries.any?{|pair| !pair[0].html_safe?}).to eq(false)
376
+ expect(countries.any? { |pair| !pair[0].html_safe? }).to eq(false)
375
377
  end
376
378
 
377
379
  it 'should return an alphabetized list of all country names translated to current locale with ISOCODE alpha2' do
378
- ISO3166.configuration.locales = [:es, :de, :en]
380
+ ISO3166.configuration.locales = %i[es de en]
379
381
 
380
382
  countries = ISO3166::Country.all_names_with_codes(:es)
381
383
  expect(countries).to be_an(Array)
@@ -395,7 +397,7 @@ describe ISO3166::Country do
395
397
  end
396
398
 
397
399
  it 'should return an alphabetized list of all country names translated to current locale with ISOCODE alpha2' do
398
- ISO3166.configuration.locales = [:es, :de, :en]
400
+ ISO3166.configuration.locales = %i[es de en]
399
401
 
400
402
  countries = ISO3166::Country.all_names_with_codes(:es)
401
403
  expect(countries).to be_an(Array)
@@ -407,7 +409,7 @@ describe ISO3166::Country do
407
409
 
408
410
  describe 'translation' do
409
411
  it 'should return the localized name for a country to the selected locale' do
410
- ISO3166.configuration.locales = [:es, :de, :en]
412
+ ISO3166.configuration.locales = %i[es de en]
411
413
  countries = ISO3166::Country.new(:de).translation('de')
412
414
  expect(countries).to be_an(String)
413
415
  expect(countries).to eq('Deutschland')
@@ -426,7 +428,7 @@ describe ISO3166::Country do
426
428
 
427
429
  context 'should return variant locales' do
428
430
  it 'should return different value for Chinese variants' do
429
- ISO3166.configuration.locales = [:'zh-cn', :'zh-hk', :'zh-tw']
431
+ ISO3166.configuration.locales = %i[zh-cn zh-hk zh-tw]
430
432
  name_cn = ISO3166::Country['TW'].translation('zh-cn')
431
433
  name_hk = ISO3166::Country['TW'].translation('zh-hk')
432
434
  name_tw = ISO3166::Country['TW'].translation('zh-tw')
@@ -434,7 +436,7 @@ describe ISO3166::Country do
434
436
  end
435
437
 
436
438
  it 'should return different value for Portuguese variants' do
437
- ISO3166.configuration.locales = [:pt, :'pt-br']
439
+ ISO3166.configuration.locales = %i[pt pt-br]
438
440
  name_pt = ISO3166::Country['SG'].translation('pt')
439
441
  name_br = ISO3166::Country['SG'].translation('pt-br')
440
442
  expect([name_pt, name_br].uniq.size).to eql 2
@@ -447,7 +449,7 @@ describe ISO3166::Country do
447
449
  countries = ISO3166::Country.translations('fr')
448
450
  expect(countries).to be_an(Hash)
449
451
  expect(countries.first[0]).to eq('AW')
450
- expect(countries.first).to eq(%w(AW Aruba))
452
+ expect(countries.first).to eq(%w[AW Aruba])
451
453
  # countries missing the desired locale will not be added to the list
452
454
  # so all 250 countries may not be returned, 'fr' returns 249, for example
453
455
  expect(countries.size).to eq(NUM_OF_COUNTRIES)
@@ -457,7 +459,7 @@ describe ISO3166::Country do
457
459
  countries = ISO3166::Country.translations
458
460
  expect(countries).to be_an(Hash)
459
461
  expect(countries.first[0]).to eq('AW')
460
- expect(countries.first).to eq(%w(AW Aruba))
462
+ expect(countries.first).to eq(%w[AW Aruba])
461
463
  expect(countries.size).to eq(NUM_OF_COUNTRIES)
462
464
  end
463
465
  end
@@ -648,7 +650,9 @@ describe ISO3166::Country do
648
650
 
649
651
  context 'when finding by invalid attribute' do
650
652
  it 'should raise an error' do
651
- expect { ISO3166::Country.find_by_invalid('invalid') }.to raise_error(RuntimeError, "Invalid attribute name 'invalid'")
653
+ expect { ISO3166::Country.find_by_invalid('invalid') }.to(
654
+ raise_error(RuntimeError, "Invalid attribute name 'invalid'")
655
+ )
652
656
  end
653
657
  end
654
658
 
@@ -713,6 +717,49 @@ describe ISO3166::Country do
713
717
  end
714
718
  end
715
719
 
720
+ describe '#find_country_by_any_name' do
721
+ context 'when search name found' do
722
+ let(:uk) { ISO3166::Country.find_country_by_any_name('United Kingdom') }
723
+
724
+ it 'should be a country instance' do
725
+ expect(uk).to be_a(ISO3166::Country)
726
+ expect(uk.alpha2).to eq('GB')
727
+ end
728
+ end
729
+
730
+ context 'when search lowercase name found' do
731
+ let(:uk) { ISO3166::Country.find_country_by_any_name('united kingdom') }
732
+
733
+ it 'should be a country instance' do
734
+ expect(uk).to be_a(ISO3166::Country)
735
+ expect(uk.alpha2).to eq('GB')
736
+ end
737
+ end
738
+
739
+ context 'when the search term contains comma' do
740
+ let(:korea) { ISO3166::Country.find_country_by_any_name('Korea, Republic of') }
741
+
742
+ it 'should be a country instance' do
743
+ expect(korea).to be_a(ISO3166::Country)
744
+ expect(korea.alpha2).to eq('KR')
745
+ end
746
+ end
747
+
748
+ context 'when search translation found' do
749
+ before do
750
+ ISO3166.configure do |config|
751
+ config.locales = [:bs]
752
+ end
753
+ end
754
+ let(:uk) { ISO3166::Country.find_country_by_any_name('Velika Britanija') }
755
+
756
+ it 'should be a country instance' do
757
+ expect(uk).to be_a(ISO3166::Country)
758
+ expect(uk.alpha2).to eq('GB')
759
+ end
760
+ end
761
+ end
762
+
716
763
  context 'regression test for #388' do
717
764
  let(:no_country) { ISO3166::Country.find_country_by_translated_names(nil) }
718
765
 
@@ -729,6 +776,7 @@ describe ISO3166::Country do
729
776
  expect { uk }.to raise_error(RuntimeError)
730
777
  end
731
778
  end
779
+
732
780
  context 'when search name not found' do
733
781
  let(:bogus) { ISO3166::Country.find_country_by_unofficial_names('Does not exist') }
734
782
 
@@ -785,8 +833,9 @@ describe ISO3166::Country do
785
833
 
786
834
  context 'when finding by invalid attribute' do
787
835
  it 'should raise an error' do
788
- expect { ISO3166::Country.find_country_by_invalid('invalid') }.to raise_error(RuntimeError,
789
- "Invalid attribute name 'invalid'")
836
+ expect { ISO3166::Country.find_country_by_invalid('invalid') }.to(
837
+ raise_error(RuntimeError, "Invalid attribute name 'invalid'")
838
+ )
790
839
  end
791
840
  end
792
841
 
@@ -848,7 +897,7 @@ describe ISO3166::Country do
848
897
  end
849
898
 
850
899
  describe 'names in Data' do
851
- it 'should be unique (to allow .find_by_name work properly)' do
900
+ it 'should be unique (to allow .find_by_any_name work properly)' do
852
901
  names = ISO3166::Data.cache.map do |_k, v|
853
902
  [v['iso_short_name'], v['unofficial_names']].flatten.uniq
854
903
  end.flatten
@@ -947,7 +996,7 @@ describe ISO3166::Country do
947
996
 
948
997
  it 'should contain all keys for vat_rates' do
949
998
  expect(belgium.vat_rates).to be_a(Hash)
950
- expect(belgium.vat_rates.keys).to eq(%w(standard reduced super_reduced parking))
999
+ expect(belgium.vat_rates.keys).to eq(%w[standard reduced super_reduced parking])
951
1000
  end
952
1001
 
953
1002
  it 'should return an array of reduced vat rates' do
@@ -1021,7 +1070,7 @@ describe ISO3166::Country do
1021
1070
 
1022
1071
  subject { ISO3166::Country.pluck(*args) }
1023
1072
 
1024
- it "returns empty arrays" do
1073
+ it 'returns empty arrays' do
1025
1074
  expect(subject.first).to be_empty
1026
1075
  expect(subject.last).to be_empty
1027
1076
  end
@@ -1029,9 +1078,9 @@ describe ISO3166::Country do
1029
1078
  context "when asking for alpha2, alpha3 and iso_short_name" do
1030
1079
  let(:args) { [:alpha2, :alpha3, :iso_short_name] }
1031
1080
 
1032
- it "returns the correct values" do
1033
- expect(subject.first).to eq(["AD", "AND", "Andorra"])
1034
- expect(subject.last).to eq(["ZW", "ZWE", "Zimbabwe"])
1081
+ it 'returns the correct values' do
1082
+ expect(subject.first).to eq(%w[AD AND Andorra])
1083
+ expect(subject.last).to eq(%w[ZW ZWE Zimbabwe])
1035
1084
  end
1036
1085
  end
1037
1086
  end
data/spec/data_spec.rb CHANGED
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
  require 'benchmark'
4
5
 
@@ -10,13 +11,13 @@ describe ISO3166::Data do
10
11
 
11
12
  it 'can load selective locales' do
12
13
  # ISO3166::Data.update_cache
13
- ISO3166.configuration.locales = [:es, :de, :en]
14
+ ISO3166.configuration.locales = %i[es de en]
14
15
  data = ISO3166::Data.new('US').call
15
16
  expect(data['translated_names'].size).to eq 3
16
17
  end
17
18
 
18
19
  it 'can load selective locales and reload efficiently' do
19
- ISO3166.configuration.locales = [:es, :de, :en]
20
+ ISO3166.configuration.locales = %i[es de en]
20
21
  data = ISO3166::Data.new('US').call
21
22
  expect(data['translations']).to eq('de' => 'Vereinigte Staaten', 'es' => 'Estados Unidos', 'en' => 'United States')
22
23
  expect(data['translated_names'].sort).to eq ['Vereinigte Staaten', 'Estados Unidos', 'United States'].sort
@@ -35,7 +36,7 @@ describe ISO3166::Data do
35
36
 
36
37
  it 'locales will load prior to return results' do
37
38
  # require 'memory_profiler'
38
- ISO3166.configuration.locales = [:es, :de, :en]
39
+ ISO3166.configuration.locales = %i[es de en]
39
40
  # report = MemoryProfiler.report do
40
41
  ISO3166::Data.update_cache
41
42
  # end
@@ -44,7 +45,12 @@ describe ISO3166::Data do
44
45
  ISO3166::Data.update_cache
45
46
 
46
47
  ISO3166.configure do |config|
47
- 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]
48
+ config.locales = %i[af am ar as az be bg bn br bs ca cs cy da de dz el en
49
+ eo es et eu fa fi fo fr ga gl gu he hi hr hu hy ia id
50
+ is it ja ka kk km kn ko ku lt lv mi mk ml mn mr ms mt
51
+ nb ne nl nn oc or pa pl ps pt ro ru rw si sk sl so sq
52
+ sr sv sw ta te th ti tk tl tr tt ug uk ve vi wa wo xh
53
+ zh zu]
48
54
  end
49
55
  # puts Benchmark.measure {ISO3166::Data.update_cache}
50
56
 
@@ -61,32 +67,32 @@ describe ISO3166::Data do
61
67
 
62
68
  it 'locales will load prior and be cached' do
63
69
  ISO3166.reset
64
- ISO3166.configuration.locales = [:es, :de, :en]
65
- expect(ISO3166::Data.send(:locales_to_load)).to eql(%w(es de en))
70
+ ISO3166.configuration.locales = %i[es de en]
71
+ expect(ISO3166::Data.send(:locales_to_load)).to eql(%w[es de en])
66
72
  ISO3166::Data.update_cache
67
- ISO3166.configuration.locales = [:es, :de, :en]
73
+ ISO3166.configuration.locales = %i[es de en]
68
74
  expect(ISO3166::Data.send(:locales_to_load)).to eql([])
69
75
  end
70
76
 
71
77
  it 'locales will load prior and be cached' do
72
78
  ISO3166.reset
73
- ISO3166.configuration.locales = [:es, :de, :en]
79
+ ISO3166.configuration.locales = %i[es de en]
74
80
  expect(ISO3166::Data.send(:locales_to_remove)).to eql([])
75
81
  expect(ISO3166::Country.new('DE').translation('de')).to eq 'Deutschland'
76
82
  ISO3166::Data.update_cache
77
- ISO3166.configuration.locales = [:es, :en]
83
+ ISO3166.configuration.locales = %i[es en]
78
84
  expect(ISO3166::Data.send(:locales_to_remove)).to eql(['de'])
79
85
  expect(ISO3166::Country.new('DE').translation('de')).to eq nil
80
86
  end
81
87
 
82
88
  describe '#load_cache' do
83
89
  it 'will return an empty hash for an unsupported locale' do
84
- file_array = %w(locales unsupported.json)
90
+ file_array = %w[locales unsupported.json]
85
91
  expect(ISO3166::Data.send(:load_cache, file_array)).to eql({})
86
92
  end
87
93
 
88
94
  it 'will return json for a supported locale' do
89
- file_array = %w(locales en.json)
95
+ file_array = %w[locales en.json]
90
96
  expect(ISO3166::Data.send(:load_cache, file_array)).not_to be_empty
91
97
  end
92
98
  end
@@ -97,8 +103,8 @@ describe ISO3166::Data do
97
103
  alpha2: 'TW',
98
104
  iso_short_name: 'NEW Taiwan',
99
105
  subdivisions: {
100
- CHA: {name: 'New Changhua'},
101
- CYI: {name: 'New Municipality'}
106
+ CHA: { name: 'New Changhua' },
107
+ CYI: { name: 'New Municipality' }
102
108
  },
103
109
  translations: {
104
110
  'en' => 'NEW Taiwan',
@@ -116,8 +122,8 @@ describe ISO3166::Data do
116
122
  expect(subject.iso_short_name).to eq 'NEW Taiwan'
117
123
  expect(subject.translations).to eq('en' => 'NEW Taiwan',
118
124
  'de' => 'NEW Taiwan')
119
- expect(subject.subdivisions).to eq('CHA' => ISO3166::Subdivision.new({name: 'New Changhua', code: 'CHA'}),
120
- 'CYI' => ISO3166::Subdivision.new({name: 'New Municipality', code: 'CYI'}))
125
+ expect(subject.subdivisions).to eq('CHA' => ISO3166::Subdivision.new({ name: 'New Changhua', code: 'CHA' }),
126
+ 'CYI' => ISO3166::Subdivision.new({ name: 'New Municipality', code: 'CYI' }))
121
127
  end
122
128
  end
123
129
 
@@ -127,8 +133,8 @@ describe ISO3166::Data do
127
133
  alpha2: 'LOL',
128
134
  iso_short_name: 'Happy Country',
129
135
  subdivisions: {
130
- LOL1: {name: 'Happy sub1'},
131
- LOL2: {name: 'Happy sub2'}
136
+ LOL1: { name: 'Happy sub1' },
137
+ LOL2: { name: 'Happy sub2' }
132
138
  },
133
139
  translations: {
134
140
  'en' => 'Happy Country',
data/spec/mongoid_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
- require File.expand_path('../../lib/countries/mongoid', __FILE__)
4
+ require File.expand_path('../lib/countries/mongoid', __dir__)
5
5
 
6
6
  describe 'Mongoid support' do
7
7
  let(:britain) { ISO3166::Country.new('GB') }
data/spec/perf_spec.rb CHANGED
@@ -1,18 +1,18 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
1
+ # frozen_string_literal: true
3
2
 
4
- describe ISO3166::Data, perf: true, order: :defined do
3
+ require 'spec_helper'
5
4
 
6
- ALL_LOCALES = [
7
- :af, :am, :ar, :as, :az, :be, :bg, :bn, :br, :bs, :ca, :cs, :cy, :da, :de,
8
- :dz, :el, :en, :eo, :es, :et, :eu, :fa, :fi, :fo, :fr, :ga, :gl, :gu, :he,
9
- :hi, :hr, :hu, :hy, :ia, :id, :is, :it, :ja, :ka, :kk, :km, :kn, :ko, :ku,
10
- :lt, :lv, :mi, :mk, :ml, :mn, :mr, :ms, :mt, :nb, :ne, :nl, :nn, :oc, :or,
11
- :pa, :pl, :ps, :pt, :ro, :ru, :rw, :si, :sk, :sl, :so, :sq, :sr, :sv, :sw,
12
- :ta, :te, :th, :ti, :tk, :tl, :tr, :tt, :ug, :uk, :ve, :vi, :wa, :wo, :xh,
13
- :zh, :zu
14
- ].freeze
5
+ ALL_LOCALES = %i[
6
+ af am ar as az be bg bn br bs ca cs cy da de
7
+ dz el en eo es et eu fa fi fo fr ga gl gu he
8
+ hi hr hu hy ia id is it ja ka kk km kn ko ku
9
+ lt lv mi mk ml mn mr ms mt nb ne nl nn oc or
10
+ pa pl ps pt ro ru rw si sk sl so sq sr sv sw
11
+ ta te th ti tk tl tr tt ug uk ve vi wa wo xh
12
+ zh zu
13
+ ].freeze
15
14
 
15
+ describe ISO3166::Data, perf: true, order: :defined do
16
16
  def perf_report(_name)
17
17
  require 'benchmark'
18
18
  require 'memory_profiler'
@@ -28,7 +28,7 @@ describe ISO3166::Data, perf: true, order: :defined do
28
28
 
29
29
  # print a flat profile to text
30
30
  printer = RubyProf::FlatPrinter.new(result)
31
- printer.print(STDOUT)
31
+ printer.print($stdout)
32
32
  end
33
33
 
34
34
  it 'responds to call' do
@@ -40,12 +40,12 @@ describe ISO3166::Data, perf: true, order: :defined do
40
40
  end
41
41
 
42
42
  it 'locales will load prior to return results' do
43
- ISO3166.configuration.locales = [:es, :de, :en]
43
+ ISO3166.configuration.locales = %i[es de en]
44
44
  report = MemoryProfiler.report do
45
45
  ISO3166::Data.update_cache
46
46
  end
47
47
 
48
- report.pretty_print(to_file: 'tmp/memory/3_locales')
48
+ report.pretty_print(to_file: 'tmp/3_locales.txt')
49
49
  puts Benchmark.measure { ISO3166::Data.update_cache }
50
50
 
51
51
  ISO3166.configure do |config|
@@ -57,7 +57,7 @@ describe ISO3166::Data, perf: true, order: :defined do
57
57
  ISO3166::Data.update_cache
58
58
  end
59
59
 
60
- report.pretty_print(to_file: 'tmp/memory/all_locales')
60
+ report.pretty_print(to_file: 'tmp/all_locales.txt')
61
61
  end
62
62
 
63
63
  it 'loades a specfic country quickly' do
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'countries'
2
4
  RSpec.configure do |config|
3
5
  config.filter_run :focus
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -23,9 +23,11 @@ describe ISO3166::Subdivision do
23
23
  describe 'state codes' do
24
24
  it 'should all be strings' do
25
25
  countries.each do |country|
26
- expect(country.subdivisions.keys).to all(be_a(String)), \
27
- "Expected #{country.alpha2.inspect} to have string subdivision" \
28
- "codes but had #{country.subdivisions.keys.inspect}"
26
+ expect(country.subdivisions.keys).to(
27
+ all(be_a(String)),
28
+ "Expected #{country.alpha2.inspect} to have string subdivision \
29
+ codes but had #{country.subdivisions.keys.inspect}"
30
+ )
29
31
  end
30
32
  end
31
33
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe 'Accessing ISO3166::Country instances data in multiple threads' do
2
4
  before do
3
5
  if Thread.respond_to?(:report_on_exception)
@@ -12,7 +14,7 @@ describe 'Accessing ISO3166::Country instances data in multiple threads' do
12
14
  nthreads = 100
13
15
  threads = []
14
16
 
15
- alpha2_codes = ['us', 'es', 'nl', 'ca', 'de', 'fr', 'mx', 'ru', 'ch', 'jp']
17
+ alpha2_codes = %w[us es nl ca de fr mx ru ch jp]
16
18
 
17
19
  nthreads.times do
18
20
  threads << Thread.new do
@@ -31,7 +33,7 @@ describe 'Accessing ISO3166::Country instances data in multiple threads' do
31
33
  expect { create_countries_threaded }.to_not raise_error
32
34
  end
33
35
 
34
- it "raises NoMethodError when not using a mutex" do
36
+ it 'raises NoMethodError when not using a mutex' do
35
37
  allow(ISO3166::Data).to receive(:use_mutex?).and_return(false)
36
38
 
37
39
  expect { create_countries_threaded }.to raise_error(NoMethodError)
@@ -43,4 +45,3 @@ describe 'Accessing ISO3166::Country instances data in multiple threads' do
43
45
  end
44
46
  end
45
47
  end
46
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe 'timezone Country class' do
2
4
  context "when loaded via 'timezone'" do
3
5
  require 'tzinfo'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: countries
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.3
4
+ version: 5.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Robinson
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2022-03-24 00:00:00.000000000 Z
14
+ date: 2022-06-02 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: i18n_data
@@ -42,7 +42,7 @@ dependencies:
42
42
  - !ruby/object:Gem::Version
43
43
  version: '1.1'
44
44
  - !ruby/object:Gem::Dependency
45
- name: rspec
45
+ name: activesupport
46
46
  requirement: !ruby/object:Gem::Requirement
47
47
  requirements:
48
48
  - - ">="
@@ -56,33 +56,33 @@ dependencies:
56
56
  - !ruby/object:Gem::Version
57
57
  version: '3'
58
58
  - !ruby/object:Gem::Dependency
59
- name: activesupport
59
+ name: nokogiri
60
60
  requirement: !ruby/object:Gem::Requirement
61
61
  requirements:
62
62
  - - ">="
63
63
  - !ruby/object:Gem::Version
64
- version: '3'
64
+ version: '1.8'
65
65
  type: :development
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
69
  - - ">="
70
70
  - !ruby/object:Gem::Version
71
- version: '3'
71
+ version: '1.8'
72
72
  - !ruby/object:Gem::Dependency
73
- name: nokogiri
73
+ name: rspec
74
74
  requirement: !ruby/object:Gem::Requirement
75
75
  requirements:
76
76
  - - ">="
77
77
  - !ruby/object:Gem::Version
78
- version: '1.8'
78
+ version: '3'
79
79
  type: :development
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
82
82
  requirements:
83
83
  - - ">="
84
84
  - !ruby/object:Gem::Version
85
- version: '1.8'
85
+ version: '3'
86
86
  description: All sorts of useful information about every country packaged as pretty
87
87
  little country objects. It includes data from ISO 3166
88
88
  email:
@@ -93,6 +93,7 @@ executables: []
93
93
  extensions: []
94
94
  extra_rdoc_files: []
95
95
  files:
96
+ - ".github/workflows/codeql-analysis.yml"
96
97
  - ".github/workflows/tests.yml"
97
98
  - ".gitignore"
98
99
  - ".rspec"
@@ -103,6 +104,7 @@ files:
103
104
  - LICENSE
104
105
  - README.markdown
105
106
  - Rakefile
107
+ - UPGRADE.md
106
108
  - bin/console
107
109
  - countries.gemspec
108
110
  - lib/countries.rb
@@ -244,6 +246,7 @@ files:
244
246
  - lib/countries/country/class_methods.rb
245
247
  - lib/countries/country/currency_methods.rb
246
248
  - lib/countries/country/emoji.rb
249
+ - lib/countries/country/finder_methods.rb
247
250
  - lib/countries/data.rb
248
251
  - lib/countries/data/countries/AD.yaml
249
252
  - lib/countries/data/countries/AE.yaml
@@ -705,7 +708,6 @@ files:
705
708
  - lib/countries/iso3166.rb
706
709
  - lib/countries/kwarg_struct.rb
707
710
  - lib/countries/mongoid.rb
708
- - lib/countries/setup.rb
709
711
  - lib/countries/sources.rb
710
712
  - lib/countries/sources/cldr/downloader.rb
711
713
  - lib/countries/sources/cldr/subdivision.rb
@@ -737,6 +739,7 @@ metadata:
737
739
  changelog_uri: https://github.com/countries/countries/blob/master/CHANGELOG.md
738
740
  source_code_uri: https://github.com/countries/countries
739
741
  wiki_uri: https://github.com/countries/countries/wiki
742
+ rubygems_mfa_required: 'true'
740
743
  post_install_message:
741
744
  rdoc_options: []
742
745
  require_paths:
@@ -745,14 +748,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
745
748
  requirements:
746
749
  - - ">="
747
750
  - !ruby/object:Gem::Version
748
- version: '2.5'
751
+ version: '2.7'
749
752
  required_rubygems_version: !ruby/object:Gem::Requirement
750
753
  requirements:
751
754
  - - ">="
752
755
  - !ruby/object:Gem::Version
753
756
  version: '0'
754
757
  requirements: []
755
- rubygems_version: 3.3.3
758
+ rubygems_version: 3.3.7
756
759
  signing_key:
757
760
  specification_version: 4
758
761
  summary: Gives you a country object full of all sorts of useful information.
@@ -1,18 +0,0 @@
1
- module ISO3166
2
- ##
3
- # <b>DEPRECATED:</b> Please use <tt>Data</tt> instead.
4
- # TODO: Remove at version 2.1
5
- # Handles building the in memory store of countries data
6
- class Setup
7
- # <b>DEPRECATED:</b> Please use <tt>Data.codes</tt> instead.
8
- def codes
9
- warn '[DEPRECATION] `Setup.codes` is deprecated. Please use `Data.codes` instead.'
10
- Data.codes
11
- end
12
-
13
- def data
14
- warn "[DEPRECATION] `Setup.new.data` is deprecated without replacement
15
- data is now loaded per locale Data.new(:en).call"
16
- end
17
- end
18
- end