countries 5.4.0 → 5.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +61 -0
- data/.github/workflows/tests.yml +4 -0
- data/.gitignore +0 -1
- data/.rubocop.yml +17 -8
- data/CHANGELOG.md +8 -0
- data/Gemfile +1 -2
- data/Gemfile.lock +84 -0
- data/README.md +41 -1
- data/Rakefile +2 -3
- data/countries.gemspec +1 -1
- data/lib/countries/cache/countries.json +1 -1
- data/lib/countries/country/class_methods.rb +22 -3
- data/lib/countries/country/country_subdivision_methods.rb +82 -0
- data/lib/countries/country/currency_methods.rb +0 -1
- data/lib/countries/country/finder_methods.rb +2 -4
- data/lib/countries/country.rb +13 -53
- data/lib/countries/data/countries/AR.yaml +1 -0
- data/lib/countries/data/countries/AU.yaml +1 -0
- data/lib/countries/data/countries/BR.yaml +1 -0
- data/lib/countries/data/countries/CA.yaml +2 -0
- data/lib/countries/data/countries/CN.yaml +1 -0
- data/lib/countries/data/countries/DE.yaml +2 -0
- data/lib/countries/data/countries/FR.yaml +2 -0
- data/lib/countries/data/countries/GB.yaml +2 -0
- data/lib/countries/data/countries/ID.yaml +1 -0
- data/lib/countries/data/countries/IN.yaml +1 -0
- data/lib/countries/data/countries/IT.yaml +2 -0
- data/lib/countries/data/countries/JP.yaml +2 -0
- data/lib/countries/data/countries/KR.yaml +1 -0
- data/lib/countries/data/countries/MX.yaml +1 -0
- data/lib/countries/data/countries/RU.yaml +1 -0
- data/lib/countries/data/countries/SA.yaml +1 -0
- data/lib/countries/data/countries/TR.yaml +1 -0
- data/lib/countries/data/countries/US.yaml +2 -0
- data/lib/countries/data/countries/ZA.yaml +1 -0
- data/lib/countries/data/locales_methods.rb +23 -0
- data/lib/countries/data/subdivision_methods.rb +30 -0
- data/lib/countries/data/subdivisions/AD.yaml +7 -0
- data/lib/countries/data/subdivisions/AE.yaml +18 -0
- data/lib/countries/data/subdivisions/AF.yaml +167 -2
- data/lib/countries/data/subdivisions/AG.yaml +9 -0
- data/lib/countries/data/subdivisions/AL.yaml +57 -0
- data/lib/countries/data/subdivisions/AM.yaml +34 -0
- data/lib/countries/data/subdivisions/AO.yaml +36 -0
- data/lib/countries/data/subdivisions/AR.yaml +46 -0
- data/lib/countries/data/subdivisions/AT.yaml +28 -0
- data/lib/countries/data/subdivisions/AU.yaml +29 -0
- data/lib/countries/data/subdivisions/AZ.yaml +239 -0
- data/lib/countries/data/subdivisions/BA.yaml +5 -0
- data/lib/countries/data/subdivisions/BB.yaml +4 -0
- data/lib/countries/data/subdivisions/BD.yaml +139 -0
- data/lib/countries/data/subdivisions/BE.yaml +34 -0
- data/lib/countries/data/subdivisions/BF.yaml +56 -0
- data/lib/countries/data/subdivisions/BG.yaml +30 -0
- data/lib/countries/data/subdivisions/BH.yaml +13 -0
- data/lib/countries/data/subdivisions/BI.yaml +54 -0
- data/lib/countries/data/subdivisions/BJ.yaml +22 -0
- data/lib/countries/data/subdivisions/BN.yaml +9 -0
- data/lib/countries/data/subdivisions/BO.yaml +35 -0
- data/lib/countries/data/subdivisions/BQ.yaml +4 -0
- data/lib/countries/data/subdivisions/BR.yaml +14 -0
- data/lib/countries/data/subdivisions/BS.yaml +24 -0
- data/lib/countries/data/subdivisions/BT.yaml +24 -0
- data/lib/countries/data/subdivisions/BW.yaml +24 -0
- data/lib/countries/data/subdivisions/BY.yaml +5 -0
- data/lib/countries/data/subdivisions/BZ.yaml +3 -0
- data/lib/countries/data/subdivisions/CA.yaml +24 -0
- data/lib/countries/data/subdivisions/CD.yaml +77 -0
- data/lib/countries/data/subdivisions/CF.yaml +15 -0
- data/lib/countries/data/subdivisions/CG.yaml +18 -0
- data/lib/countries/data/subdivisions/CH.yaml +92 -0
- data/lib/countries/data/subdivisions/CI.yaml +65 -0
- data/lib/countries/data/subdivisions/CL.yaml +45 -2
- data/lib/countries/data/subdivisions/CM.yaml +22 -0
- data/lib/countries/data/subdivisions/CN.yaml +98 -0
- data/lib/countries/data/subdivisions/CO.yaml +68 -0
- data/lib/countries/data/subdivisions/CR.yaml +14 -0
- data/lib/countries/data/subdivisions/CU.yaml +42 -0
- data/lib/countries/data/subdivisions/CV.yaml +32 -0
- data/lib/countries/data/subdivisions/CY.yaml +18 -0
- data/lib/countries/data/subdivisions/CZ.yaml +227 -0
- data/lib/countries/data/subdivisions/DE.yaml +31 -0
- data/lib/countries/data/subdivisions/DJ.yaml +16 -0
- data/lib/countries/data/subdivisions/DK.yaml +13 -0
- data/lib/countries/data/subdivisions/DM.yaml +1 -0
- data/lib/countries/data/subdivisions/DO.yaml +102 -0
- data/lib/countries/data/subdivisions/DZ.yaml +104 -0
- data/lib/countries/data/subdivisions/EC.yaml +72 -0
- data/lib/countries/data/subdivisions/EE.yaml +6 -0
- data/lib/countries/data/subdivisions/EG.yaml +54 -0
- data/lib/countries/data/subdivisions/ER.yaml +2 -0
- data/lib/countries/data/subdivisions/ES.yaml +252 -0
- data/lib/countries/data/subdivisions/ET.yaml +27 -0
- data/lib/countries/data/subdivisions/FI.yaml +78 -0
- data/lib/countries/data/subdivisions/FJ.yaml +30 -0
- data/lib/countries/data/subdivisions/FM.yaml +11 -0
- data/lib/countries/data/subdivisions/FR.yaml +332 -1
- data/lib/countries/data/subdivisions/GA.yaml +24 -0
- data/lib/countries/data/subdivisions/GB.yaml +488 -0
- data/lib/countries/data/subdivisions/GD.yaml +10 -0
- data/lib/countries/data/subdivisions/GE.yaml +34 -0
- data/lib/countries/data/subdivisions/GH.yaml +79 -0
- data/lib/countries/data/subdivisions/GL.yaml +58 -0
- data/lib/countries/data/subdivisions/GM.yaml +10 -0
- data/lib/countries/data/subdivisions/GN.yaml +65 -0
- data/lib/countries/data/subdivisions/GQ.yaml +36 -0
- data/lib/countries/data/subdivisions/GR.yaml +41 -0
- data/lib/countries/data/subdivisions/GW.yaml +24 -0
- data/lib/countries/data/subdivisions/GY.yaml +31 -0
- data/lib/countries/data/subdivisions/HN.yaml +21 -0
- data/lib/countries/data/subdivisions/HR.yaml +82 -0
- data/lib/countries/data/subdivisions/HT.yaml +14 -0
- data/lib/countries/data/subdivisions/HU.yaml +94 -0
- data/lib/countries/data/subdivisions/ID.yaml +99 -0
- data/lib/countries/data/subdivisions/IE.yaml +39 -0
- data/lib/countries/data/subdivisions/IL.yaml +15 -0
- data/lib/countries/data/subdivisions/IN.yaml +210 -0
- data/lib/countries/data/subdivisions/IQ.yaml +59 -0
- data/lib/countries/data/subdivisions/IR.yaml +2 -0
- data/lib/countries/data/subdivisions/IS.yaml +560 -0
- data/lib/countries/data/subdivisions/IT.yaml +321 -0
- data/lib/countries/data/subdivisions/JM.yaml +22 -0
- data/lib/countries/data/subdivisions/JO.yaml +16 -0
- data/lib/countries/data/subdivisions/JP.yaml +42 -0
- data/lib/countries/data/subdivisions/KE.yaml +298 -0
- data/lib/countries/data/subdivisions/KG.yaml +28 -0
- data/lib/countries/data/subdivisions/KH.yaml +108 -0
- data/lib/countries/data/subdivisions/KI.yaml +6 -0
- data/lib/countries/data/subdivisions/KM.yaml +4 -0
- data/lib/countries/data/subdivisions/KN.yaml +6 -0
- data/lib/countries/data/subdivisions/KP.yaml +42 -0
- data/lib/countries/data/subdivisions/KR.yaml +36 -0
- data/lib/countries/data/subdivisions/KW.yaml +5 -0
- data/lib/countries/data/subdivisions/KZ.yaml +113 -0
- data/lib/countries/data/subdivisions/LA.yaml +49 -0
- data/lib/countries/data/subdivisions/LB.yaml +28 -0
- data/lib/countries/data/subdivisions/LC.yaml +6 -0
- data/lib/countries/data/subdivisions/LI.yaml +37 -0
- data/lib/countries/data/subdivisions/LK.yaml +67 -0
- data/lib/countries/data/subdivisions/LR.yaml +16 -0
- data/lib/countries/data/subdivisions/LS.yaml +23 -0
- data/lib/countries/data/subdivisions/LT.yaml +315 -0
- data/lib/countries/data/subdivisions/LU.yaml +31 -0
- data/lib/countries/data/subdivisions/LV.yaml +83 -0
- data/lib/countries/data/subdivisions/LY.yaml +16 -0
- data/lib/countries/data/subdivisions/MA.yaml +827 -12
- data/lib/countries/data/subdivisions/MC.yaml +47 -0
- data/lib/countries/data/subdivisions/MD.yaml +41 -0
- data/lib/countries/data/subdivisions/ME.yaml +83 -0
- data/lib/countries/data/subdivisions/MG.yaml +21 -0
- data/lib/countries/data/subdivisions/MH.yaml +70 -0
- data/lib/countries/data/subdivisions/MK.yaml +505 -0
- data/lib/countries/data/subdivisions/ML.yaml +33 -0
- data/lib/countries/data/subdivisions/MM.yaml +51 -0
- data/lib/countries/data/subdivisions/MN.yaml +94 -0
- data/lib/countries/data/subdivisions/MR.yaml +32 -0
- data/lib/countries/data/subdivisions/MT.yaml +126 -0
- data/lib/countries/data/subdivisions/MU.yaml +21 -0
- data/lib/countries/data/subdivisions/MV.yaml +20 -0
- data/lib/countries/data/subdivisions/MW.yaml +52 -0
- data/lib/countries/data/subdivisions/MX.yaml +23 -0
- data/lib/countries/data/subdivisions/MY.yaml +24 -0
- data/lib/countries/data/subdivisions/MZ.yaml +20 -0
- data/lib/countries/data/subdivisions/NA.yaml +28 -0
- data/lib/countries/data/subdivisions/NE.yaml +9 -0
- data/lib/countries/data/subdivisions/NG.yaml +89 -0
- data/lib/countries/data/subdivisions/NI.yaml +25 -0
- data/lib/countries/data/subdivisions/NL.yaml +24 -0
- data/lib/countries/data/subdivisions/NO.yaml +138 -1
- data/lib/countries/data/subdivisions/NP.yaml +9 -0
- data/lib/countries/data/subdivisions/NR.yaml +19 -0
- data/lib/countries/data/subdivisions/NZ.yaml +34 -0
- data/lib/countries/data/subdivisions/OM.yaml +10 -0
- data/lib/countries/data/subdivisions/PA.yaml +27 -0
- data/lib/countries/data/subdivisions/PE.yaml +24 -0
- data/lib/countries/data/subdivisions/PG.yaml +46 -0
- data/lib/countries/data/subdivisions/PH.yaml +293 -0
- data/lib/countries/data/subdivisions/PK.yaml +22 -0
- data/lib/countries/data/subdivisions/PL.yaml +141 -0
- data/lib/countries/data/subdivisions/PS.yaml +41 -0
- data/lib/countries/data/subdivisions/PT.yaml +36 -0
- data/lib/countries/data/subdivisions/PW.yaml +24 -0
- data/lib/countries/data/subdivisions/PY.yaml +21 -0
- data/lib/countries/data/subdivisions/QA.yaml +26 -0
- data/lib/countries/data/subdivisions/RO.yaml +189 -0
- data/lib/countries/data/subdivisions/RS.yaml +112 -0
- data/lib/countries/data/subdivisions/RU.yaml +123 -0
- data/lib/countries/data/subdivisions/RW.yaml +7 -0
- data/lib/countries/data/subdivisions/SA.yaml +38 -0
- data/lib/countries/data/subdivisions/SB.yaml +11 -0
- data/lib/countries/data/subdivisions/SC.yaml +45 -0
- data/lib/countries/data/subdivisions/SD.yaml +15 -0
- data/lib/countries/data/subdivisions/SE.yaml +42 -0
- data/lib/countries/data/subdivisions/SG.yaml +8 -0
- data/lib/countries/data/subdivisions/SH.yaml +6 -0
- data/lib/countries/data/subdivisions/SI.yaml +735 -0
- data/lib/countries/data/subdivisions/SK.yaml +22 -0
- data/lib/countries/data/subdivisions/SL.yaml +7 -0
- data/lib/countries/data/subdivisions/SM.yaml +19 -0
- data/lib/countries/data/subdivisions/SN.yaml +43 -0
- data/lib/countries/data/subdivisions/SO.yaml +71 -0
- data/lib/countries/data/subdivisions/SR.yaml +17 -0
- data/lib/countries/data/subdivisions/SS.yaml +4 -0
- data/lib/countries/data/subdivisions/ST.yaml +127 -0
- data/lib/countries/data/subdivisions/SV.yaml +20 -0
- data/lib/countries/data/subdivisions/SY.yaml +53 -0
- data/lib/countries/data/subdivisions/SZ.yaml +18 -0
- data/lib/countries/data/subdivisions/TD.yaml +51 -0
- data/lib/countries/data/subdivisions/TG.yaml +13 -0
- data/lib/countries/data/subdivisions/TH.yaml +231 -0
- data/lib/countries/data/subdivisions/TJ.yaml +15 -0
- data/lib/countries/data/subdivisions/TL.yaml +38 -0
- data/lib/countries/data/subdivisions/TM.yaml +15 -0
- data/lib/countries/data/subdivisions/TN.yaml +25 -0
- data/lib/countries/data/subdivisions/TO.yaml +1 -0
- data/lib/countries/data/subdivisions/TR.yaml +93 -0
- data/lib/countries/data/subdivisions/TT.yaml +25 -0
- data/lib/countries/data/subdivisions/TV.yaml +25 -0
- data/lib/countries/data/subdivisions/TW.yaml +106 -0
- data/lib/countries/data/subdivisions/TZ.yaml +38 -0
- data/lib/countries/data/subdivisions/UA.yaml +86 -4
- data/lib/countries/data/subdivisions/UG.yaml +262 -0
- data/lib/countries/data/subdivisions/UM.yaml +4 -0
- data/lib/countries/data/subdivisions/US.yaml +118 -0
- data/lib/countries/data/subdivisions/UY.yaml +27 -0
- data/lib/countries/data/subdivisions/UZ.yaml +65 -0
- data/lib/countries/data/subdivisions/VC.yaml +6 -0
- data/lib/countries/data/subdivisions/VE.yaml +33 -0
- data/lib/countries/data/subdivisions/VN.yaml +131 -0
- data/lib/countries/data/subdivisions/VU.yaml +8 -0
- data/lib/countries/data/subdivisions/WS.yaml +18 -0
- data/lib/countries/data/subdivisions/YE.yaml +16 -0
- data/lib/countries/data/subdivisions/ZA.yaml +5 -0
- data/lib/countries/data/subdivisions/ZM.yaml +24 -0
- data/lib/countries/data/subdivisions/ZW.yaml +21 -0
- data/lib/countries/data.rb +19 -50
- data/lib/countries/global.rb +0 -1
- data/lib/countries/iso3166.rb +3 -0
- data/lib/countries/sources/cldr/subdivision.rb +1 -1
- data/lib/countries/subdivision.rb +5 -0
- data/lib/countries/tasks/postal_codes.rake +5 -1
- data/lib/countries/version.rb +1 -1
- data/spec/country_spec.rb +118 -22
- data/spec/data_spec.rb +12 -8
- data/spec/spec_helper.rb +4 -0
- data/spec/subdivision_spec.rb +8 -0
- metadata +23 -16
- data/.rubocop_todo.yml +0 -19
- data/lib/countries/tasks/geocoding.rake +0 -106
data/spec/data_spec.rb
CHANGED
@@ -128,7 +128,7 @@ describe ISO3166::Data do
|
|
128
128
|
|
129
129
|
it 'can be done' do
|
130
130
|
data = ISO3166::Data.new('TW').call
|
131
|
-
ISO3166.configuration.locales = [
|
131
|
+
ISO3166.configuration.locales = %i[es de de]
|
132
132
|
expect(data['iso_short_name']).to eq 'NEW Taiwan'
|
133
133
|
expect(subject.iso_short_name).to eq 'NEW Taiwan'
|
134
134
|
expect(subject.translations).to eq('en' => 'NEW Taiwan',
|
@@ -205,18 +205,18 @@ describe ISO3166::Data do
|
|
205
205
|
it 'has a non-blank code for all subdivisions' do
|
206
206
|
Dir['lib/countries/data/subdivisions/*.yaml'].each do |file|
|
207
207
|
data = YAML.load_file(file)
|
208
|
-
expect(data.values.none?{|s| s['code'].nil? }).to be_truthy, "empty subdivision code in #{file}"
|
208
|
+
expect(data.values.none? { |s| s['code'].nil? }).to be_truthy, "empty subdivision code in #{file}"
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|
212
212
|
it 'has a non-blank, lowercase and snake_case type for all subdivisions' do
|
213
213
|
Dir['lib/countries/data/subdivisions/*.yaml'].each do |file|
|
214
214
|
data = YAML.load_file(file)
|
215
|
-
no_type = data.select{|
|
215
|
+
no_type = data.select { |_k, v| v['type'].nil? }
|
216
216
|
expect(no_type).to be_empty, "empty subdivision type in #{file} - #{no_type.keys}"
|
217
|
-
uppercase = data.select{|
|
217
|
+
uppercase = data.select { |_k, v| v['type'] =~ /[A-Z]/ }
|
218
218
|
expect(uppercase).to be_empty, "uppercase characters in subdivision type in #{file} - #{uppercase.keys}"
|
219
|
-
spaces = data.select{|
|
219
|
+
spaces = data.select { |_k, v| v['type'] =~ /\s/ }
|
220
220
|
expect(spaces).to be_empty, "whitespace characters in subdivision type in #{file} - #{spaces.keys}"
|
221
221
|
end
|
222
222
|
end
|
@@ -224,7 +224,7 @@ describe ISO3166::Data do
|
|
224
224
|
it 'has a non-blank name for all subdivisions' do
|
225
225
|
Dir['lib/countries/data/subdivisions/*.yaml'].each do |file|
|
226
226
|
data = YAML.load_file(file)
|
227
|
-
expect(data.values.none?{|s| s['name'].nil? }).to be_truthy, "empty subdivision name in #{file}"
|
227
|
+
expect(data.values.none? { |s| s['name'].nil? }).to be_truthy, "empty subdivision name in #{file}"
|
228
228
|
end
|
229
229
|
end
|
230
230
|
end
|
@@ -232,13 +232,17 @@ describe ISO3166::Data do
|
|
232
232
|
context 'cached country subdivision data' do
|
233
233
|
it 'has a non-blank code for all subdivisions' do
|
234
234
|
ISO3166::Country.all.each do |country|
|
235
|
-
expect(country.subdivisions.values.none?
|
235
|
+
expect(country.subdivisions.values.none? do |s|
|
236
|
+
s['code'].nil?
|
237
|
+
end).to be_truthy, "empty subdivision code in #{country}"
|
236
238
|
end
|
237
239
|
end
|
238
240
|
|
239
241
|
it 'has a non-blank name for all subdivisions' do
|
240
242
|
ISO3166::Country.all.each do |country|
|
241
|
-
expect(country.subdivisions.values.none?
|
243
|
+
expect(country.subdivisions.values.none? do |s|
|
244
|
+
s['name'].nil?
|
245
|
+
end).to be_truthy, "empty subdivision name in #{country}"
|
242
246
|
end
|
243
247
|
end
|
244
248
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/subdivision_spec.rb
CHANGED
@@ -31,4 +31,12 @@ describe ISO3166::Subdivision do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
describe 'code_with_translations' do
|
36
|
+
before { ISO3166.configuration.locales = %i[en pt] }
|
37
|
+
it 'returns a hash' do
|
38
|
+
expect(ISO3166::Country.new('IT').subdivisions['NA'].code_with_translations).to eq({ 'NA' => { 'en' => 'Naples',
|
39
|
+
'pt' => 'Nápoles' } })
|
40
|
+
end
|
41
|
+
end
|
34
42
|
end
|
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: 5.
|
4
|
+
version: 5.5.0
|
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: 2023-
|
14
|
+
date: 2023-06-17 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: unaccent
|
@@ -69,6 +69,20 @@ dependencies:
|
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '3'
|
72
|
+
- !ruby/object:Gem::Dependency
|
73
|
+
name: simplecov
|
74
|
+
requirement: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - "~>"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0.22'
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - "~>"
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0.22'
|
72
86
|
description: All sorts of useful information about every country packaged as pretty
|
73
87
|
little country objects. It includes data from ISO 3166
|
74
88
|
email:
|
@@ -79,15 +93,16 @@ executables: []
|
|
79
93
|
extensions: []
|
80
94
|
extra_rdoc_files: []
|
81
95
|
files:
|
96
|
+
- ".codeclimate.yml"
|
82
97
|
- ".github/FUNDING.yml"
|
83
98
|
- ".github/workflows/codeql-analysis.yml"
|
84
99
|
- ".github/workflows/tests.yml"
|
85
100
|
- ".gitignore"
|
86
101
|
- ".rspec"
|
87
102
|
- ".rubocop.yml"
|
88
|
-
- ".rubocop_todo.yml"
|
89
103
|
- CHANGELOG.md
|
90
104
|
- Gemfile
|
105
|
+
- Gemfile.lock
|
91
106
|
- LICENSE
|
92
107
|
- README.md
|
93
108
|
- Rakefile
|
@@ -230,6 +245,7 @@ files:
|
|
230
245
|
- lib/countries/configuration.rb
|
231
246
|
- lib/countries/country.rb
|
232
247
|
- lib/countries/country/class_methods.rb
|
248
|
+
- lib/countries/country/country_subdivision_methods.rb
|
233
249
|
- lib/countries/country/currency_methods.rb
|
234
250
|
- lib/countries/country/emoji.rb
|
235
251
|
- lib/countries/country/finder_methods.rb
|
@@ -483,6 +499,8 @@ files:
|
|
483
499
|
- lib/countries/data/countries/ZA.yaml
|
484
500
|
- lib/countries/data/countries/ZM.yaml
|
485
501
|
- lib/countries/data/countries/ZW.yaml
|
502
|
+
- lib/countries/data/locales_methods.rb
|
503
|
+
- lib/countries/data/subdivision_methods.rb
|
486
504
|
- lib/countries/data/subdivisions/AD.yaml
|
487
505
|
- lib/countries/data/subdivisions/AE.yaml
|
488
506
|
- lib/countries/data/subdivisions/AF.yaml
|
@@ -825,7 +843,6 @@ files:
|
|
825
843
|
- lib/countries/sources/local/subdivision.rb
|
826
844
|
- lib/countries/structure.rb
|
827
845
|
- lib/countries/subdivision.rb
|
828
|
-
- lib/countries/tasks/geocoding.rake
|
829
846
|
- lib/countries/tasks/postal_codes.rake
|
830
847
|
- lib/countries/timezones.rb
|
831
848
|
- lib/countries/translations.rb
|
@@ -864,18 +881,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
864
881
|
- !ruby/object:Gem::Version
|
865
882
|
version: '0'
|
866
883
|
requirements: []
|
867
|
-
rubygems_version: 3.4.
|
884
|
+
rubygems_version: 3.4.12
|
868
885
|
signing_key:
|
869
886
|
specification_version: 4
|
870
887
|
summary: Gives you a country object full of all sorts of useful information.
|
871
|
-
test_files:
|
872
|
-
- spec/00_global_spec.rb
|
873
|
-
- spec/configuration_spec.rb
|
874
|
-
- spec/country_spec.rb
|
875
|
-
- spec/data_spec.rb
|
876
|
-
- spec/mongoid_spec.rb
|
877
|
-
- spec/perf_spec.rb
|
878
|
-
- spec/spec_helper.rb
|
879
|
-
- spec/subdivision_spec.rb
|
880
|
-
- spec/thread_safety_spec.rb
|
881
|
-
- spec/timezone_spec.rb
|
888
|
+
test_files: []
|
data/.rubocop_todo.yml
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# This configuration was generated by
|
2
|
-
# `rubocop --auto-gen-config`
|
3
|
-
# on 2022-01-07 11:03:11 UTC using RuboCop version 1.24.1.
|
4
|
-
# The point is for the user to remove these configuration records
|
5
|
-
# one by one as the offenses are removed from the code base.
|
6
|
-
# Note that changes in the inspected code, or installation of new
|
7
|
-
# versions of RuboCop, may require this file to be generated again.
|
8
|
-
|
9
|
-
|
10
|
-
# Offense count: 3
|
11
|
-
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
|
12
|
-
Metrics/AbcSize:
|
13
|
-
Max: 33
|
14
|
-
|
15
|
-
# Enable after the doc branch is merged
|
16
|
-
Style/Documentation:
|
17
|
-
Enabled: false
|
18
|
-
# Exclude:
|
19
|
-
# - 'spec/**/*'
|
@@ -1,106 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'geocoder'
|
4
|
-
require 'retryable'
|
5
|
-
|
6
|
-
Geocoder.configure(
|
7
|
-
lookup: :google,
|
8
|
-
timeout: 10,
|
9
|
-
api_key: GOOGLE_API_KEY
|
10
|
-
)
|
11
|
-
|
12
|
-
# raise on geocoding errors such as query limit exceeded
|
13
|
-
Geocoder.configure(always_raise: :all)
|
14
|
-
# Try to geocode a given query, on exceptions it retries up to 3 times then gives up.
|
15
|
-
# @param [String] query string to geocode
|
16
|
-
# @return [Hash] first valid result or nil
|
17
|
-
def geocode(query, params)
|
18
|
-
Retryable.retryable(tries: 3, sleep: ->(n) { 2**n }) do
|
19
|
-
Geocoder.search(query, params: params).first
|
20
|
-
end
|
21
|
-
rescue Geocoder::Error, Geocoder::LookupTimeout => e
|
22
|
-
warn "Attempts exceeded for query #{query}, last error was #{e.message}"
|
23
|
-
nil
|
24
|
-
end
|
25
|
-
|
26
|
-
def load_country_yaml(alpha2)
|
27
|
-
YAML.load_file(File.join(ISO3166_ROOT_PATH, 'lib', 'countries', 'data', 'countries', "#{alpha2}.yaml"))
|
28
|
-
end
|
29
|
-
|
30
|
-
def save_country_yaml(alpha2, data)
|
31
|
-
File.write(File.join(ISO3166_ROOT_PATH, 'lib', 'countries', 'data', 'countries', "#{alpha2}.yaml"), data.to_yaml)
|
32
|
-
end
|
33
|
-
|
34
|
-
def country_codes
|
35
|
-
@country_codes ||= Dir['lib/countries/data/countries/*.yaml'].map { |x| File.basename(x, File.extname(x)) }.uniq
|
36
|
-
end
|
37
|
-
|
38
|
-
namespace :geocode do
|
39
|
-
desc 'Retrieve and store countries coordinates'
|
40
|
-
task :fetch_countries do
|
41
|
-
require 'countries'
|
42
|
-
# Iterate over countries
|
43
|
-
ISO3166::Country.all.each do |country|
|
44
|
-
code = country.alpha2
|
45
|
-
# Load unmutated yaml file.
|
46
|
-
data = load_country_yaml(country.alpha2)
|
47
|
-
|
48
|
-
next unless (result = geocode(country.iso_short_name, {region: country.alpha2}))
|
49
|
-
|
50
|
-
unless result.types.include?('country')
|
51
|
-
puts "WARNING:: Geocoder returned something that was not a country for #{country.alpha2}"
|
52
|
-
end
|
53
|
-
geometry = result.geometry
|
54
|
-
|
55
|
-
# Extract center point data
|
56
|
-
if geometry['location']
|
57
|
-
data[code]['geo']['latitude'] = geometry['location']['lat']
|
58
|
-
data[code]['geo']['longitude'] = geometry['location']['lng']
|
59
|
-
end
|
60
|
-
|
61
|
-
# Extract bounding box data
|
62
|
-
next unless geometry['bounds']
|
63
|
-
|
64
|
-
data[code]['geo']['bounds'] = geometry['bounds']
|
65
|
-
data[code]['geo']['min_latitude'] = geometry['bounds']['southwest']['lat']
|
66
|
-
data[code]['geo']['min_longitude'] = geometry['bounds']['southwest']['lng']
|
67
|
-
data[code]['geo']['max_latitude'] = geometry['bounds']['northeast']['lat']
|
68
|
-
data[code]['geo']['max_longitude'] = geometry['bounds']['northeast']['lng']
|
69
|
-
|
70
|
-
# Persist
|
71
|
-
save_country_yaml(code, data)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
desc 'Retrieve and store subdivisions coordinates'
|
76
|
-
task :fetch_subdivisions do
|
77
|
-
require_relative '../../countries'
|
78
|
-
# Iterate all countries with subdivisions
|
79
|
-
ISO3166::Country.all.select(&:subdivisions?).each do |c|
|
80
|
-
# Iterate subdivisions
|
81
|
-
state_data = c.subdivisions.dup
|
82
|
-
state_data.reject { |_, data| data['geo'] }.each do |code, _|
|
83
|
-
location = "#{c.alpha2}-#{code}"
|
84
|
-
|
85
|
-
next unless (result = geocode(location, { region: c.alpha2 }))
|
86
|
-
|
87
|
-
geometry = result.geometry
|
88
|
-
if geometry['location']
|
89
|
-
state_data[code]['geo'] ||= {}
|
90
|
-
state_data[code]['geo']['latitude'] = geometry['location']['lat']
|
91
|
-
state_data[code]['geo']['longitude'] = geometry['location']['lng']
|
92
|
-
end
|
93
|
-
|
94
|
-
next unless geometry['bounds']
|
95
|
-
|
96
|
-
state_data[code]['geo']['min_latitude'] = geometry['bounds']['southwest']['lat']
|
97
|
-
state_data[code]['geo']['min_longitude'] = geometry['bounds']['southwest']['lng']
|
98
|
-
state_data[code]['geo']['max_latitude'] = geometry['bounds']['northeast']['lat']
|
99
|
-
state_data[code]['geo']['max_longitude'] = geometry['bounds']['northeast']['lng']
|
100
|
-
end
|
101
|
-
# Write updated YAML for current country
|
102
|
-
out = File.join(ISO3166_ROOT_PATH, 'lib', 'countries', 'data', 'subdivisions', "#{c.alpha2}.yaml")
|
103
|
-
File.write(out, state_data.to_yaml)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|