countries 4.2.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) 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 +33 -5
  7. data/Gemfile +5 -3
  8. data/LICENSE +3 -1
  9. data/README.markdown +34 -18
  10. data/Rakefile +15 -31
  11. data/bin/console +1 -0
  12. data/countries.gemspec +12 -10
  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/AE.yaml +1 -1
  24. data/lib/countries/data/countries/KN.yaml +0 -1
  25. data/lib/countries/data/subdivisions/AD.yaml +21 -21
  26. data/lib/countries/data/subdivisions/AF.yaml +2 -2
  27. data/lib/countries/data/subdivisions/AG.yaml +1 -1
  28. data/lib/countries/data/subdivisions/AI.yaml +98 -98
  29. data/lib/countries/data/subdivisions/AL.yaml +82 -626
  30. data/lib/countries/data/subdivisions/AZ.yaml +5 -5
  31. data/lib/countries/data/subdivisions/BA.yaml +11 -11
  32. data/lib/countries/data/subdivisions/BD.yaml +8 -8
  33. data/lib/countries/data/subdivisions/BE.yaml +2 -2
  34. data/lib/countries/data/subdivisions/BF.yaml +13 -13
  35. data/lib/countries/data/subdivisions/BI.yaml +3 -3
  36. data/lib/countries/data/subdivisions/BM.yaml +77 -77
  37. data/lib/countries/data/subdivisions/BS.yaml +22 -22
  38. data/lib/countries/data/subdivisions/BW.yaml +7 -7
  39. data/lib/countries/data/subdivisions/BY.yaml +1 -1
  40. data/lib/countries/data/subdivisions/CD.yaml +19 -19
  41. data/lib/countries/data/subdivisions/CG.yaml +1 -1
  42. data/lib/countries/data/subdivisions/CI.yaml +14 -14
  43. data/lib/countries/data/subdivisions/CK.yaml +77 -77
  44. data/lib/countries/data/subdivisions/CN.yaml +0 -107
  45. data/lib/countries/data/subdivisions/CV.yaml +9 -9
  46. data/lib/countries/data/subdivisions/DK.yaml +1 -0
  47. data/lib/countries/data/subdivisions/DO.yaml +11 -11
  48. data/lib/countries/data/subdivisions/EE.yaml +78 -2
  49. data/lib/countries/data/subdivisions/EH.yaml +12 -12
  50. data/lib/countries/data/subdivisions/ES.yaml +17 -17
  51. data/lib/countries/data/subdivisions/FI.yaml +16 -16
  52. data/lib/countries/data/subdivisions/FJ.yaml +14 -14
  53. data/lib/countries/data/subdivisions/GB.yaml +21 -20
  54. data/lib/countries/data/subdivisions/GH.yaml +7 -7
  55. data/lib/countries/data/subdivisions/GL.yaml +6 -6
  56. data/lib/countries/data/subdivisions/GN.yaml +7 -7
  57. data/lib/countries/data/subdivisions/GQ.yaml +1 -0
  58. data/lib/countries/data/subdivisions/GR.yaml +1 -1
  59. data/lib/countries/data/subdivisions/GW.yaml +3 -3
  60. data/lib/countries/data/subdivisions/HT.yaml +1 -1
  61. data/lib/countries/data/subdivisions/ID.yaml +41 -41
  62. data/lib/countries/data/subdivisions/IE.yaml +1 -2
  63. data/lib/countries/data/subdivisions/IN.yaml +4 -3
  64. data/lib/countries/data/subdivisions/IQ.yaml +1 -1
  65. data/lib/countries/data/subdivisions/IR.yaml +2 -1
  66. data/lib/countries/data/subdivisions/IS.yaml +72 -0
  67. data/lib/countries/data/subdivisions/IT.yaml +7 -8
  68. data/lib/countries/data/subdivisions/KG.yaml +1 -1
  69. data/lib/countries/data/subdivisions/KH.yaml +1 -1
  70. data/lib/countries/data/subdivisions/KN.yaml +2 -2
  71. data/lib/countries/data/subdivisions/KP.yaml +12 -12
  72. data/lib/countries/data/subdivisions/KR.yaml +1 -1
  73. data/lib/countries/data/subdivisions/KZ.yaml +1 -1
  74. data/lib/countries/data/subdivisions/LA.yaml +1 -1
  75. data/lib/countries/data/subdivisions/LB.yaml +2 -2
  76. data/lib/countries/data/subdivisions/LC.yaml +10 -10
  77. data/lib/countries/data/subdivisions/LK.yaml +9 -9
  78. data/lib/countries/data/subdivisions/LR.yaml +2 -2
  79. data/lib/countries/data/subdivisions/LT.yaml +60 -60
  80. data/lib/countries/data/subdivisions/LU.yaml +1 -1
  81. data/lib/countries/data/subdivisions/LV.yaml +1 -1
  82. data/lib/countries/data/subdivisions/MA.yaml +35 -35
  83. data/lib/countries/data/subdivisions/MC.yaml +17 -17
  84. data/lib/countries/data/subdivisions/MD.yaml +740 -740
  85. data/lib/countries/data/subdivisions/ME.yaml +3 -3
  86. data/lib/countries/data/subdivisions/MH.yaml +2 -2
  87. data/lib/countries/data/subdivisions/ML.yaml +2 -2
  88. data/lib/countries/data/subdivisions/MM.yaml +1 -1
  89. data/lib/countries/data/subdivisions/MR.yaml +3 -3
  90. data/lib/countries/data/subdivisions/MV.yaml +8 -8
  91. data/lib/countries/data/subdivisions/MW.yaml +4 -4
  92. data/lib/countries/data/subdivisions/MX.yaml +1 -1
  93. data/lib/countries/data/subdivisions/NL.yaml +6 -6
  94. data/lib/countries/data/subdivisions/NO.yaml +1 -0
  95. data/lib/countries/data/subdivisions/NP.yaml +12 -12
  96. data/lib/countries/data/subdivisions/NZ.yaml +1 -1
  97. data/lib/countries/data/subdivisions/OM.yaml +6 -6
  98. data/lib/countries/data/subdivisions/PG.yaml +3 -3
  99. data/lib/countries/data/subdivisions/PH.yaml +16 -16
  100. data/lib/countries/data/subdivisions/PK.yaml +2 -2
  101. data/lib/countries/data/subdivisions/PS.yaml +16 -16
  102. data/lib/countries/data/subdivisions/QA.yaml +2 -2
  103. data/lib/countries/data/subdivisions/RS.yaml +2 -2
  104. data/lib/countries/data/subdivisions/SC.yaml +4 -2
  105. data/lib/countries/data/subdivisions/SH.yaml +1 -1
  106. data/lib/countries/data/subdivisions/SI.yaml +19 -19
  107. data/lib/countries/data/subdivisions/SJ.yaml +14 -14
  108. data/lib/countries/data/subdivisions/SL.yaml +1 -1
  109. data/lib/countries/data/subdivisions/SN.yaml +3 -3
  110. data/lib/countries/data/subdivisions/SS.yaml +10 -10
  111. data/lib/countries/data/subdivisions/ST.yaml +6 -0
  112. data/lib/countries/data/subdivisions/TD.yaml +6 -6
  113. data/lib/countries/data/subdivisions/TH.yaml +1 -1
  114. data/lib/countries/data/subdivisions/TJ.yaml +2 -2
  115. data/lib/countries/data/subdivisions/TK.yaml +21 -21
  116. data/lib/countries/data/subdivisions/TM.yaml +1 -1
  117. data/lib/countries/data/subdivisions/TT.yaml +2 -2
  118. data/lib/countries/data/subdivisions/TV.yaml +1 -1
  119. data/lib/countries/data/subdivisions/TW.yaml +3 -17
  120. data/lib/countries/data/subdivisions/TZ.yaml +5 -5
  121. data/lib/countries/data/subdivisions/UG.yaml +59 -52
  122. data/lib/countries/data/subdivisions/UM.yaml +0 -10
  123. data/lib/countries/data/subdivisions/WF.yaml +3 -13
  124. data/lib/countries/data/subdivisions/YE.yaml +3 -3
  125. data/lib/countries/data/subdivisions/ZA.yaml +2 -2
  126. data/lib/countries/data/subdivisions/ZM.yaml +1 -1
  127. data/lib/countries/data.rb +34 -37
  128. data/lib/countries/global.rb +2 -0
  129. data/lib/countries/iso3166.rb +3 -0
  130. data/lib/countries/kwarg_struct.rb +2 -0
  131. data/lib/countries/mongoid.rb +2 -0
  132. data/lib/countries/sources/cldr/downloader.rb +8 -8
  133. data/lib/countries/sources/cldr/subdivision.rb +3 -0
  134. data/lib/countries/sources/cldr/subdivision_updater.rb +23 -17
  135. data/lib/countries/sources/local/cached_loader.rb +3 -0
  136. data/lib/countries/sources/local/subdivision.rb +5 -2
  137. data/lib/countries/sources.rb +2 -0
  138. data/lib/countries/structure.rb +1 -1
  139. data/lib/countries/subdivision.rb +2 -0
  140. data/lib/countries/tasks/geocoding.rake +15 -6
  141. data/lib/countries/tasks/postal_codes.rake +5 -3
  142. data/lib/countries/timezones.rb +5 -2
  143. data/lib/countries/translations.rb +2 -0
  144. data/lib/countries/version.rb +3 -1
  145. data/lib/countries.rb +2 -0
  146. data/spec/00_global_spec.rb +2 -0
  147. data/spec/configuration_spec.rb +11 -5
  148. data/spec/country_spec.rb +71 -22
  149. data/spec/data_spec.rb +24 -18
  150. data/spec/mongoid_spec.rb +2 -2
  151. data/spec/perf_spec.rb +16 -16
  152. data/spec/spec_helper.rb +2 -0
  153. data/spec/subdivision_spec.rb +6 -4
  154. data/spec/thread_safety_spec.rb +4 -3
  155. data/spec/timezone_spec.rb +2 -0
  156. metadata +18 -45
  157. data/lib/countries/data/subdivisions/AS.yaml +0 -85
  158. data/lib/countries/data/subdivisions/AW.yaml +0 -9
  159. data/lib/countries/data/subdivisions/AX.yaml +0 -51
  160. data/lib/countries/data/subdivisions/BL.yaml +0 -11
  161. data/lib/countries/data/subdivisions/CP.yaml +0 -4
  162. data/lib/countries/data/subdivisions/CW.yaml +0 -9
  163. data/lib/countries/data/subdivisions/GF.yaml +0 -11
  164. data/lib/countries/data/subdivisions/GG.yaml +0 -155
  165. data/lib/countries/data/subdivisions/GP.yaml +0 -11
  166. data/lib/countries/data/subdivisions/GU.yaml +0 -275
  167. data/lib/countries/data/subdivisions/HK.yaml +0 -267
  168. data/lib/countries/data/subdivisions/IC.yaml +0 -4
  169. data/lib/countries/data/subdivisions/IM.yaml +0 -337
  170. data/lib/countries/data/subdivisions/JE.yaml +0 -169
  171. data/lib/countries/data/subdivisions/MF.yaml +0 -9
  172. data/lib/countries/data/subdivisions/MO.yaml +0 -9
  173. data/lib/countries/data/subdivisions/MP.yaml +0 -71
  174. data/lib/countries/data/subdivisions/MQ.yaml +0 -11
  175. data/lib/countries/data/subdivisions/MS.yaml +0 -43
  176. data/lib/countries/data/subdivisions/NC.yaml +0 -57
  177. data/lib/countries/data/subdivisions/PF.yaml +0 -81
  178. data/lib/countries/data/subdivisions/PM.yaml +0 -39
  179. data/lib/countries/data/subdivisions/PR.yaml +0 -1107
  180. data/lib/countries/data/subdivisions/RE.yaml +0 -11
  181. data/lib/countries/data/subdivisions/SX.yaml +0 -9
  182. data/lib/countries/data/subdivisions/TA.yaml +0 -4
  183. data/lib/countries/data/subdivisions/TF.yaml +0 -67
  184. data/lib/countries/data/subdivisions/VI.yaml +0 -57
  185. data/lib/countries/data/subdivisions/YT.yaml +0 -247
  186. 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'