countries 5.4.0 → 5.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (250) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +61 -0
  3. data/.github/workflows/tests.yml +4 -0
  4. data/.gitignore +0 -1
  5. data/.rubocop.yml +17 -8
  6. data/CHANGELOG.md +8 -0
  7. data/Gemfile +1 -2
  8. data/Gemfile.lock +84 -0
  9. data/README.md +41 -1
  10. data/Rakefile +2 -3
  11. data/countries.gemspec +1 -1
  12. data/lib/countries/cache/countries.json +1 -1
  13. data/lib/countries/country/class_methods.rb +22 -3
  14. data/lib/countries/country/country_subdivision_methods.rb +82 -0
  15. data/lib/countries/country/currency_methods.rb +0 -1
  16. data/lib/countries/country/finder_methods.rb +2 -4
  17. data/lib/countries/country.rb +13 -53
  18. data/lib/countries/data/countries/AR.yaml +1 -0
  19. data/lib/countries/data/countries/AU.yaml +1 -0
  20. data/lib/countries/data/countries/BR.yaml +1 -0
  21. data/lib/countries/data/countries/CA.yaml +2 -0
  22. data/lib/countries/data/countries/CN.yaml +1 -0
  23. data/lib/countries/data/countries/DE.yaml +2 -0
  24. data/lib/countries/data/countries/FR.yaml +2 -0
  25. data/lib/countries/data/countries/GB.yaml +2 -0
  26. data/lib/countries/data/countries/ID.yaml +1 -0
  27. data/lib/countries/data/countries/IN.yaml +1 -0
  28. data/lib/countries/data/countries/IT.yaml +2 -0
  29. data/lib/countries/data/countries/JP.yaml +2 -0
  30. data/lib/countries/data/countries/KR.yaml +1 -0
  31. data/lib/countries/data/countries/MX.yaml +1 -0
  32. data/lib/countries/data/countries/RU.yaml +1 -0
  33. data/lib/countries/data/countries/SA.yaml +1 -0
  34. data/lib/countries/data/countries/TR.yaml +1 -0
  35. data/lib/countries/data/countries/US.yaml +2 -0
  36. data/lib/countries/data/countries/ZA.yaml +1 -0
  37. data/lib/countries/data/locales_methods.rb +23 -0
  38. data/lib/countries/data/subdivision_methods.rb +30 -0
  39. data/lib/countries/data/subdivisions/AD.yaml +7 -0
  40. data/lib/countries/data/subdivisions/AE.yaml +18 -0
  41. data/lib/countries/data/subdivisions/AF.yaml +167 -2
  42. data/lib/countries/data/subdivisions/AG.yaml +9 -0
  43. data/lib/countries/data/subdivisions/AL.yaml +57 -0
  44. data/lib/countries/data/subdivisions/AM.yaml +34 -0
  45. data/lib/countries/data/subdivisions/AO.yaml +36 -0
  46. data/lib/countries/data/subdivisions/AR.yaml +46 -0
  47. data/lib/countries/data/subdivisions/AT.yaml +28 -0
  48. data/lib/countries/data/subdivisions/AU.yaml +29 -0
  49. data/lib/countries/data/subdivisions/AZ.yaml +239 -0
  50. data/lib/countries/data/subdivisions/BA.yaml +5 -0
  51. data/lib/countries/data/subdivisions/BB.yaml +4 -0
  52. data/lib/countries/data/subdivisions/BD.yaml +139 -0
  53. data/lib/countries/data/subdivisions/BE.yaml +34 -0
  54. data/lib/countries/data/subdivisions/BF.yaml +56 -0
  55. data/lib/countries/data/subdivisions/BG.yaml +30 -0
  56. data/lib/countries/data/subdivisions/BH.yaml +13 -0
  57. data/lib/countries/data/subdivisions/BI.yaml +54 -0
  58. data/lib/countries/data/subdivisions/BJ.yaml +22 -0
  59. data/lib/countries/data/subdivisions/BN.yaml +9 -0
  60. data/lib/countries/data/subdivisions/BO.yaml +35 -0
  61. data/lib/countries/data/subdivisions/BQ.yaml +4 -0
  62. data/lib/countries/data/subdivisions/BR.yaml +14 -0
  63. data/lib/countries/data/subdivisions/BS.yaml +24 -0
  64. data/lib/countries/data/subdivisions/BT.yaml +24 -0
  65. data/lib/countries/data/subdivisions/BW.yaml +24 -0
  66. data/lib/countries/data/subdivisions/BY.yaml +5 -0
  67. data/lib/countries/data/subdivisions/BZ.yaml +3 -0
  68. data/lib/countries/data/subdivisions/CA.yaml +24 -0
  69. data/lib/countries/data/subdivisions/CD.yaml +77 -0
  70. data/lib/countries/data/subdivisions/CF.yaml +15 -0
  71. data/lib/countries/data/subdivisions/CG.yaml +18 -0
  72. data/lib/countries/data/subdivisions/CH.yaml +92 -0
  73. data/lib/countries/data/subdivisions/CI.yaml +65 -0
  74. data/lib/countries/data/subdivisions/CL.yaml +45 -2
  75. data/lib/countries/data/subdivisions/CM.yaml +22 -0
  76. data/lib/countries/data/subdivisions/CN.yaml +98 -0
  77. data/lib/countries/data/subdivisions/CO.yaml +68 -0
  78. data/lib/countries/data/subdivisions/CR.yaml +14 -0
  79. data/lib/countries/data/subdivisions/CU.yaml +42 -0
  80. data/lib/countries/data/subdivisions/CV.yaml +32 -0
  81. data/lib/countries/data/subdivisions/CY.yaml +18 -0
  82. data/lib/countries/data/subdivisions/CZ.yaml +227 -0
  83. data/lib/countries/data/subdivisions/DE.yaml +31 -0
  84. data/lib/countries/data/subdivisions/DJ.yaml +16 -0
  85. data/lib/countries/data/subdivisions/DK.yaml +13 -0
  86. data/lib/countries/data/subdivisions/DM.yaml +1 -0
  87. data/lib/countries/data/subdivisions/DO.yaml +102 -0
  88. data/lib/countries/data/subdivisions/DZ.yaml +104 -0
  89. data/lib/countries/data/subdivisions/EC.yaml +72 -0
  90. data/lib/countries/data/subdivisions/EE.yaml +6 -0
  91. data/lib/countries/data/subdivisions/EG.yaml +54 -0
  92. data/lib/countries/data/subdivisions/ER.yaml +2 -0
  93. data/lib/countries/data/subdivisions/ES.yaml +252 -0
  94. data/lib/countries/data/subdivisions/ET.yaml +27 -0
  95. data/lib/countries/data/subdivisions/FI.yaml +78 -0
  96. data/lib/countries/data/subdivisions/FJ.yaml +30 -0
  97. data/lib/countries/data/subdivisions/FM.yaml +11 -0
  98. data/lib/countries/data/subdivisions/FR.yaml +332 -1
  99. data/lib/countries/data/subdivisions/GA.yaml +24 -0
  100. data/lib/countries/data/subdivisions/GB.yaml +488 -0
  101. data/lib/countries/data/subdivisions/GD.yaml +10 -0
  102. data/lib/countries/data/subdivisions/GE.yaml +34 -0
  103. data/lib/countries/data/subdivisions/GH.yaml +79 -0
  104. data/lib/countries/data/subdivisions/GL.yaml +58 -0
  105. data/lib/countries/data/subdivisions/GM.yaml +10 -0
  106. data/lib/countries/data/subdivisions/GN.yaml +65 -0
  107. data/lib/countries/data/subdivisions/GQ.yaml +36 -0
  108. data/lib/countries/data/subdivisions/GR.yaml +41 -0
  109. data/lib/countries/data/subdivisions/GW.yaml +24 -0
  110. data/lib/countries/data/subdivisions/GY.yaml +31 -0
  111. data/lib/countries/data/subdivisions/HN.yaml +21 -0
  112. data/lib/countries/data/subdivisions/HR.yaml +82 -0
  113. data/lib/countries/data/subdivisions/HT.yaml +14 -0
  114. data/lib/countries/data/subdivisions/HU.yaml +94 -0
  115. data/lib/countries/data/subdivisions/ID.yaml +99 -0
  116. data/lib/countries/data/subdivisions/IE.yaml +39 -0
  117. data/lib/countries/data/subdivisions/IL.yaml +15 -0
  118. data/lib/countries/data/subdivisions/IN.yaml +210 -0
  119. data/lib/countries/data/subdivisions/IQ.yaml +59 -0
  120. data/lib/countries/data/subdivisions/IR.yaml +2 -0
  121. data/lib/countries/data/subdivisions/IS.yaml +560 -0
  122. data/lib/countries/data/subdivisions/IT.yaml +321 -0
  123. data/lib/countries/data/subdivisions/JM.yaml +22 -0
  124. data/lib/countries/data/subdivisions/JO.yaml +16 -0
  125. data/lib/countries/data/subdivisions/JP.yaml +42 -0
  126. data/lib/countries/data/subdivisions/KE.yaml +298 -0
  127. data/lib/countries/data/subdivisions/KG.yaml +28 -0
  128. data/lib/countries/data/subdivisions/KH.yaml +108 -0
  129. data/lib/countries/data/subdivisions/KI.yaml +6 -0
  130. data/lib/countries/data/subdivisions/KM.yaml +4 -0
  131. data/lib/countries/data/subdivisions/KN.yaml +6 -0
  132. data/lib/countries/data/subdivisions/KP.yaml +42 -0
  133. data/lib/countries/data/subdivisions/KR.yaml +36 -0
  134. data/lib/countries/data/subdivisions/KW.yaml +5 -0
  135. data/lib/countries/data/subdivisions/KZ.yaml +113 -0
  136. data/lib/countries/data/subdivisions/LA.yaml +49 -0
  137. data/lib/countries/data/subdivisions/LB.yaml +28 -0
  138. data/lib/countries/data/subdivisions/LC.yaml +6 -0
  139. data/lib/countries/data/subdivisions/LI.yaml +37 -0
  140. data/lib/countries/data/subdivisions/LK.yaml +67 -0
  141. data/lib/countries/data/subdivisions/LR.yaml +16 -0
  142. data/lib/countries/data/subdivisions/LS.yaml +23 -0
  143. data/lib/countries/data/subdivisions/LT.yaml +315 -0
  144. data/lib/countries/data/subdivisions/LU.yaml +31 -0
  145. data/lib/countries/data/subdivisions/LV.yaml +83 -0
  146. data/lib/countries/data/subdivisions/LY.yaml +16 -0
  147. data/lib/countries/data/subdivisions/MA.yaml +827 -12
  148. data/lib/countries/data/subdivisions/MC.yaml +47 -0
  149. data/lib/countries/data/subdivisions/MD.yaml +41 -0
  150. data/lib/countries/data/subdivisions/ME.yaml +83 -0
  151. data/lib/countries/data/subdivisions/MG.yaml +21 -0
  152. data/lib/countries/data/subdivisions/MH.yaml +70 -0
  153. data/lib/countries/data/subdivisions/MK.yaml +505 -0
  154. data/lib/countries/data/subdivisions/ML.yaml +33 -0
  155. data/lib/countries/data/subdivisions/MM.yaml +51 -0
  156. data/lib/countries/data/subdivisions/MN.yaml +94 -0
  157. data/lib/countries/data/subdivisions/MR.yaml +32 -0
  158. data/lib/countries/data/subdivisions/MT.yaml +126 -0
  159. data/lib/countries/data/subdivisions/MU.yaml +21 -0
  160. data/lib/countries/data/subdivisions/MV.yaml +20 -0
  161. data/lib/countries/data/subdivisions/MW.yaml +52 -0
  162. data/lib/countries/data/subdivisions/MX.yaml +23 -0
  163. data/lib/countries/data/subdivisions/MY.yaml +24 -0
  164. data/lib/countries/data/subdivisions/MZ.yaml +20 -0
  165. data/lib/countries/data/subdivisions/NA.yaml +28 -0
  166. data/lib/countries/data/subdivisions/NE.yaml +9 -0
  167. data/lib/countries/data/subdivisions/NG.yaml +89 -0
  168. data/lib/countries/data/subdivisions/NI.yaml +25 -0
  169. data/lib/countries/data/subdivisions/NL.yaml +24 -0
  170. data/lib/countries/data/subdivisions/NO.yaml +138 -1
  171. data/lib/countries/data/subdivisions/NP.yaml +9 -0
  172. data/lib/countries/data/subdivisions/NR.yaml +19 -0
  173. data/lib/countries/data/subdivisions/NZ.yaml +34 -0
  174. data/lib/countries/data/subdivisions/OM.yaml +10 -0
  175. data/lib/countries/data/subdivisions/PA.yaml +27 -0
  176. data/lib/countries/data/subdivisions/PE.yaml +24 -0
  177. data/lib/countries/data/subdivisions/PG.yaml +46 -0
  178. data/lib/countries/data/subdivisions/PH.yaml +293 -0
  179. data/lib/countries/data/subdivisions/PK.yaml +22 -0
  180. data/lib/countries/data/subdivisions/PL.yaml +141 -0
  181. data/lib/countries/data/subdivisions/PS.yaml +41 -0
  182. data/lib/countries/data/subdivisions/PT.yaml +36 -0
  183. data/lib/countries/data/subdivisions/PW.yaml +24 -0
  184. data/lib/countries/data/subdivisions/PY.yaml +21 -0
  185. data/lib/countries/data/subdivisions/QA.yaml +26 -0
  186. data/lib/countries/data/subdivisions/RO.yaml +189 -0
  187. data/lib/countries/data/subdivisions/RS.yaml +112 -0
  188. data/lib/countries/data/subdivisions/RU.yaml +123 -0
  189. data/lib/countries/data/subdivisions/RW.yaml +7 -0
  190. data/lib/countries/data/subdivisions/SA.yaml +38 -0
  191. data/lib/countries/data/subdivisions/SB.yaml +11 -0
  192. data/lib/countries/data/subdivisions/SC.yaml +45 -0
  193. data/lib/countries/data/subdivisions/SD.yaml +15 -0
  194. data/lib/countries/data/subdivisions/SE.yaml +42 -0
  195. data/lib/countries/data/subdivisions/SG.yaml +8 -0
  196. data/lib/countries/data/subdivisions/SH.yaml +6 -0
  197. data/lib/countries/data/subdivisions/SI.yaml +735 -0
  198. data/lib/countries/data/subdivisions/SK.yaml +22 -0
  199. data/lib/countries/data/subdivisions/SL.yaml +7 -0
  200. data/lib/countries/data/subdivisions/SM.yaml +19 -0
  201. data/lib/countries/data/subdivisions/SN.yaml +43 -0
  202. data/lib/countries/data/subdivisions/SO.yaml +71 -0
  203. data/lib/countries/data/subdivisions/SR.yaml +17 -0
  204. data/lib/countries/data/subdivisions/SS.yaml +4 -0
  205. data/lib/countries/data/subdivisions/ST.yaml +127 -0
  206. data/lib/countries/data/subdivisions/SV.yaml +20 -0
  207. data/lib/countries/data/subdivisions/SY.yaml +53 -0
  208. data/lib/countries/data/subdivisions/SZ.yaml +18 -0
  209. data/lib/countries/data/subdivisions/TD.yaml +51 -0
  210. data/lib/countries/data/subdivisions/TG.yaml +13 -0
  211. data/lib/countries/data/subdivisions/TH.yaml +231 -0
  212. data/lib/countries/data/subdivisions/TJ.yaml +15 -0
  213. data/lib/countries/data/subdivisions/TL.yaml +38 -0
  214. data/lib/countries/data/subdivisions/TM.yaml +15 -0
  215. data/lib/countries/data/subdivisions/TN.yaml +25 -0
  216. data/lib/countries/data/subdivisions/TO.yaml +1 -0
  217. data/lib/countries/data/subdivisions/TR.yaml +93 -0
  218. data/lib/countries/data/subdivisions/TT.yaml +25 -0
  219. data/lib/countries/data/subdivisions/TV.yaml +25 -0
  220. data/lib/countries/data/subdivisions/TW.yaml +106 -0
  221. data/lib/countries/data/subdivisions/TZ.yaml +38 -0
  222. data/lib/countries/data/subdivisions/UA.yaml +86 -4
  223. data/lib/countries/data/subdivisions/UG.yaml +262 -0
  224. data/lib/countries/data/subdivisions/UM.yaml +4 -0
  225. data/lib/countries/data/subdivisions/US.yaml +118 -0
  226. data/lib/countries/data/subdivisions/UY.yaml +27 -0
  227. data/lib/countries/data/subdivisions/UZ.yaml +65 -0
  228. data/lib/countries/data/subdivisions/VC.yaml +6 -0
  229. data/lib/countries/data/subdivisions/VE.yaml +33 -0
  230. data/lib/countries/data/subdivisions/VN.yaml +131 -0
  231. data/lib/countries/data/subdivisions/VU.yaml +8 -0
  232. data/lib/countries/data/subdivisions/WS.yaml +18 -0
  233. data/lib/countries/data/subdivisions/YE.yaml +16 -0
  234. data/lib/countries/data/subdivisions/ZA.yaml +5 -0
  235. data/lib/countries/data/subdivisions/ZM.yaml +24 -0
  236. data/lib/countries/data/subdivisions/ZW.yaml +21 -0
  237. data/lib/countries/data.rb +19 -50
  238. data/lib/countries/global.rb +0 -1
  239. data/lib/countries/iso3166.rb +3 -0
  240. data/lib/countries/sources/cldr/subdivision.rb +1 -1
  241. data/lib/countries/subdivision.rb +5 -0
  242. data/lib/countries/tasks/postal_codes.rake +5 -1
  243. data/lib/countries/version.rb +1 -1
  244. data/spec/country_spec.rb +118 -22
  245. data/spec/data_spec.rb +12 -8
  246. data/spec/spec_helper.rb +4 -0
  247. data/spec/subdivision_spec.rb +8 -0
  248. metadata +23 -16
  249. data/.rubocop_todo.yml +0 -19
  250. data/lib/countries/tasks/geocoding.rake +0 -106
@@ -161,6 +161,7 @@ FS:
161
161
  mk: Фристејт
162
162
  'no': Free State
163
163
  yo_BJ: Free State
164
+ ga: an Saorstát Oráisteach
164
165
  comments:
165
166
  type: province
166
167
  GP:
@@ -241,6 +242,7 @@ GP:
241
242
  mk: Гаутенг
242
243
  'no': Gauteng
243
244
  yo_BJ: Gauteng
245
+ hu: Gauteng
244
246
  comments:
245
247
  type: province
246
248
  LP:
@@ -320,6 +322,7 @@ LP:
320
322
  mk: Лимпопо
321
323
  'no': Limpopo
322
324
  yo_BJ: Limpopo
325
+ hu: Limpopo (tartomány)
323
326
  comments:
324
327
  type: province
325
328
  MP:
@@ -399,6 +402,7 @@ MP:
399
402
  mk: Мпумаланга
400
403
  'no': Mpumalanga
401
404
  yo_BJ: Mpumalanga
405
+ hu: Mpumalanga
402
406
  comments:
403
407
  type: province
404
408
  NC:
@@ -478,6 +482,7 @@ NC:
478
482
  mk: Северен Кејп
479
483
  'no': Northern Cape
480
484
  yo_BJ: Northern Cape
485
+ gl: Cabo Setentrional
481
486
  comments:
482
487
  type: province
483
488
  NW:
@@ -58,6 +58,10 @@
58
58
  ccp: Western
59
59
  hy: Արևմտյան պրովինցիա
60
60
  'no': Western
61
+ ca: Província Occidental
62
+ fa: استان غربی (زامبیا)
63
+ he: מחוז המערב
64
+ zu: Western Province, Zambiya
61
65
  comments:
62
66
  type: province
63
67
  '02':
@@ -120,6 +124,7 @@
120
124
  ccp: Central
121
125
  cs: Centrální provincie (Zambie)
122
126
  'no': Central
127
+ fa: استان مرکزی، زامبیا
123
128
  comments:
124
129
  type: province
125
130
  '03':
@@ -179,6 +184,9 @@
179
184
  zh: 东方省
180
185
  ccp: "\U0001111B\U0001112A\U00011107\U00011134\U0001111F\U0001112C\U00011107\U00011134\U00011108\U0001112C"
181
186
  'no': Eastern
187
+ ca: Província de l’Est
188
+ fa: استان شرقی (زامبیا)
189
+ he: האזור המזרחי
182
190
  comments:
183
191
  type: province
184
192
  '04':
@@ -239,6 +247,9 @@
239
247
  ccp: "\U00011123\U0001112A\U00011120\U0001111B\U0001112A\U00011123"
240
248
  ca: província de Luapula
241
249
  'no': Luapula
250
+ cs: Provincie Luapula
251
+ fa: استان لوآپولا
252
+ hu: Luapula
242
253
  comments:
243
254
  type: province
244
255
  '05':
@@ -297,6 +308,8 @@
297
308
  zh: 北方省
298
309
  ccp: "\U00011105\U0001112A\U00011116\U00011133\U00011126\U00011127\U00011122\U00011134\U0001111F\U0001112C\U00011107\U00011134\U00011108\U0001112C"
299
310
  'no': Northern
311
+ fa: استان شمالی (زامبیا)
312
+ he: אזור הצפון
300
313
  comments:
301
314
  type: province
302
315
  '06':
@@ -358,6 +371,8 @@
358
371
  ccp: "\U00011105\U0001112A\U00011116\U00011133\U00011126\U00011127\U00011122\U00011134-\U0001111B\U00011127\U0001110F\U00011128\U0001111F\U00011134\U0001111F\U0001112C\U00011107\U00011134\U00011108\U0001112C"
359
372
  yue: 西北省
360
373
  'no': North-Western
374
+ ca: Província del Nord-oest
375
+ fa: استان شمال غربی (زامبیا)
361
376
  comments:
362
377
  type: province
363
378
  '07':
@@ -418,6 +433,9 @@
418
433
  zh: 南部省
419
434
  ccp: "\U00011118\U00011127\U0001110A\U00011128\U0001111A\U00011134\U0001111F\U0001112C\U00011107\U00011134\U00011108\U0001112C"
420
435
  'no': Southern
436
+ ca: Província Meridional
437
+ fa: استان جنوبی (زامبیا)
438
+ ga: Cúige an Deiscirt
421
439
  comments:
422
440
  type: province
423
441
  '08':
@@ -480,6 +498,7 @@
480
498
  ccp: "\U00011107\U0001112E\U0001111B\U0001112C\U00011122\U00011134\U0001111D\U0001112C\U00011123\U00011134\U00011111\U00011134"
481
499
  ca: província de Copperbelt
482
500
  'no': Copperbelt
501
+ he: מחוז קופרבלט
483
502
  comments:
484
503
  type: province
485
504
  '09':
@@ -538,6 +557,9 @@
538
557
  zh: 卢萨卡省
539
558
  ccp: "\U00011123\U0001112A\U00011125\U00011107"
540
559
  'no': Lusaka
560
+ ca: Lusaka
561
+ cy: Talaith Lusaka
562
+ fa: استان لوساکا
541
563
  comments:
542
564
  type: province
543
565
  '10':
@@ -591,5 +613,7 @@
591
613
  zh: 穆欽加省
592
614
  ccp: "\U0001111F\U0001112A\U0001110C\U00011128\U00011101\U00011109"
593
615
  'no': Muchinga
616
+ cy: Talaith Muchinga
617
+ fa: استان موچینگا
594
618
  comments:
595
619
  type: province
@@ -15,8 +15,12 @@ BU:
15
15
  ru: Булавайо
16
16
  ceb: Bulawayo Province
17
17
  ar: إقليم بولاوايو
18
+ ja: ブラワヨ
18
19
  ccp: "\U0001111D\U0001112A\U00011123\U00011124\U00011103\U0001112E"
19
20
  be: Булавая
21
+ cy: Talaith Bulawayo
22
+ fr: province de Bulawayo
23
+ zh: 布拉瓦约省
20
24
  comments:
21
25
  type: province
22
26
  HA:
@@ -43,6 +47,12 @@ HA:
43
47
  nb: Harare Province
44
48
  ne: हरारे प्रदेश
45
49
  'no': Harare Province
50
+ cy: Talaith Harare
51
+ fa: استان هراره
52
+ lv: Harare
53
+ uk: Хараре
54
+ zh: 哈拉雷省
55
+ zu: Harare, Isifundazwe
46
56
  comments:
47
57
  type: province
48
58
  MA:
@@ -106,6 +116,7 @@ MA:
106
116
  sr_Latn: Manikalend
107
117
  ccp: "\U0001111F\U00011127\U0001111A\U00011128\U00011107\U00011123\U00011133\U00011120\U0001111A\U00011133\U00011113\U00011134"
108
118
  'no': Manicaland
119
+ zu: Manicaland
109
120
  comments:
110
121
  type: province
111
122
  MC:
@@ -169,6 +180,7 @@ MC:
169
180
  ccp: "\U0001111F\U00011125\U0001112E\U0001111A\U00011123\U00011133\U00011120\U0001111A\U00011133\U00011113\U00011134
170
181
  \U00011125\U0001112C\U0001111A\U00011134\U00011111\U00011133\U00011122\U00011123\U00011134"
171
182
  'no': Mashonaland Central
183
+ zu: Mashonaland Central
172
184
  comments:
173
185
  type: province
174
186
  ME:
@@ -233,6 +245,7 @@ ME:
233
245
  \U0001111B\U0001112A\U00011107\U00011134"
234
246
  he: משונאלנד מזרח פרובינציה
235
247
  'no': Mashonaland East
248
+ zu: Mashonaland East
236
249
  comments:
237
250
  type: province
238
251
  MI:
@@ -295,6 +308,7 @@ MI:
295
308
  sr_Latn: Midlends
296
309
  ccp: "\U0001111F\U00011128\U00011116\U00011134\U00011123\U00011133\U00011120\U0001111A\U00011133\U00011113\U00011134\U00011125\U00011134"
297
310
  'no': Midlands
311
+ zu: Midlands (Isifundazwe)
298
312
  comments:
299
313
  type: province
300
314
  MN:
@@ -359,6 +373,7 @@ MN:
359
373
  ccp: "\U0001111F\U00011111\U0001111D\U00011128\U00011123\U00011128\U00011123\U00011133\U00011120\U0001111A\U00011133\U00011113\U00011134
360
374
  \U00011105\U0001112A\U00011116\U00011133\U00011126\U00011127\U00011122\U00011134"
361
375
  'no': Matabeleland North
376
+ zu: Matabeleland North
362
377
  comments:
363
378
  type: province
364
379
  MS:
@@ -422,6 +437,8 @@ MS:
422
437
  ccp: "\U0001111F\U00011111\U0001111D\U00011128\U00011123\U00011128\U00011123\U00011133\U00011120\U0001111A\U00011133\U00011113\U00011134
423
438
  \U00011118\U00011127\U0001110A\U00011128\U0001111A\U00011134"
424
439
  'no': Matabeleland South
440
+ hy: Հարավային Մատաբելելենդ
441
+ zu: Matabeleland South
425
442
  comments:
426
443
  type: province
427
444
  MV:
@@ -484,6 +501,8 @@ MV:
484
501
  sr_Latn: Mašvingo
485
502
  ccp: "\U0001111F\U0001110C\U00011134\U0001111E\U00011128\U00011101\U00011109\U0001112E"
486
503
  'no': Masvingo
504
+ hy: Մասվինգո
505
+ zu: Masvingo (Isifundazwe)
487
506
  comments:
488
507
  type: province
489
508
  MW:
@@ -547,5 +566,7 @@ MW:
547
566
  ccp: "\U0001111F\U00011125\U0001112E\U0001111A\U00011123\U00011133\U00011120\U0001111A\U00011133\U00011113\U00011134
548
567
  \U0001111B\U00011127\U0001110F\U00011128\U0001111F\U00011134"
549
568
  'no': Mashonaland West
569
+ he: משונלנד-מערב
570
+ zu: Mashonaland West
550
571
  comments:
551
572
  type: province
@@ -3,6 +3,9 @@
3
3
  module ISO3166
4
4
  # Handles building the in memory store of countries data
5
5
  class Data
6
+ extend SubdivisionMethods
7
+ extend LocalesMethods
8
+
6
9
  @cache_dir = [File.dirname(__FILE__), 'cache']
7
10
  @cache = {}
8
11
  @loaded_country_codes = []
@@ -19,15 +22,13 @@ module ISO3166
19
22
  end
20
23
 
21
24
  class << self
22
-
23
25
  # Registers a new Country with custom data.
24
26
  # If you are overriding an existing country, this does not perform a deep merge so you will need to __bring in all data you wish to be available__.
25
27
  # Overriding an existing country will also remove it from the internal management of translations.
26
28
  def register(data)
27
29
  alpha2 = data[:alpha2].upcase
28
30
  @registered_data[alpha2] = deep_stringify_keys(data)
29
- @registered_data[alpha2]['translations'] = \
30
- Translations.new.merge(data['translations'] || {})
31
+ @registered_data[alpha2]['translations'] = Translations.new.merge(data['translations'] || {})
31
32
  @cache = cache.merge(@registered_data)
32
33
  end
33
34
 
@@ -70,26 +71,6 @@ module ISO3166
70
71
  File.join([@cache_dir] + file_array)
71
72
  end
72
73
 
73
- def subdivision_data(alpha2)
74
- file = subdivision_file_path(alpha2)
75
- data = File.exist?(file) ? YAML.load_file(file) : {}
76
- locales = ISO3166.configuration.locales.map(&:to_s)
77
- data.each_value{ |v| v['translations'] = v['translations'].slice(*locales)}
78
-
79
- return data
80
- end
81
-
82
- def subdivisions(alpha2)
83
- @subdivisions ||= {}
84
- @subdivisions[alpha2] ||= create_subdivisions(ISO3166::Data.subdivision_data(alpha2))
85
- end
86
-
87
- def create_subdivisions(subdivision_data)
88
- subdivision_data.each_with_object({}) do |(k, v), hash|
89
- hash[k] = Subdivision.new(v)
90
- end
91
- end
92
-
93
74
  private
94
75
 
95
76
  def load_data!
@@ -129,9 +110,7 @@ module ISO3166
129
110
  end
130
111
 
131
112
  def load_required?
132
- synchronized do
133
- @cache.empty?
134
- end
113
+ synchronized { @cache.empty? }
135
114
  end
136
115
 
137
116
  def cached_codes
@@ -147,44 +126,36 @@ module ISO3166
147
126
  !locales_to_load.empty? || !locales_to_remove.empty?
148
127
  end
149
128
 
150
- def locales_to_load
151
- requested_locales - loaded_locales
152
- end
153
-
154
- def locales_to_remove
155
- loaded_locales - requested_locales
156
- end
157
-
158
- def requested_locales
159
- ISO3166.configuration.locales.map { |l| l.to_s.downcase }
160
- end
161
-
162
- def loaded_locales
163
- ISO3166.configuration.loaded_locales.map { |l| l.to_s.downcase }
164
- end
165
-
166
129
  def load_translations(locale)
167
130
  synchronized do
168
131
  locale_names = load_cache(['locales', "#{locale}.json"])
169
132
  internal_codes.each do |alpha2|
170
- @cache[alpha2]['translations'] ||= Translations.new
171
- @cache[alpha2]['translations'][locale] = locale_names[alpha2].freeze
172
- @cache[alpha2]['translated_names'] = @cache[alpha2]['translations'].values.freeze
133
+ load_alpha2_translation_for_locale(alpha2, locale, locale_names)
173
134
  end
174
135
  ISO3166.configuration.loaded_locales << locale
175
136
  end
176
137
  end
177
138
 
139
+ def load_alpha2_translation_for_locale(alpha2, locale, locale_names)
140
+ @cache[alpha2]['translations'] ||= Translations.new
141
+ @cache[alpha2]['translations'][locale] = locale_names[alpha2].freeze
142
+ @cache[alpha2]['translated_names'] = @cache[alpha2]['translations'].values.freeze
143
+ end
144
+
178
145
  def unload_translations(locale)
179
146
  synchronized do
180
147
  internal_codes.each do |alpha2|
181
- @cache[alpha2]['translations'].delete(locale)
182
- @cache[alpha2]['translated_names'] = @cache[alpha2]['translations'].values.freeze
148
+ unload_alpha2_translation_for_locale(alpha2, locale)
183
149
  end
184
150
  ISO3166.configuration.loaded_locales.delete(locale)
185
151
  end
186
152
  end
187
153
 
154
+ def unload_alpha2_translation_for_locale(alpha2, locale)
155
+ @cache[alpha2]['translations'].delete(locale)
156
+ @cache[alpha2]['translated_names'] = @cache[alpha2]['translations'].values.freeze
157
+ end
158
+
188
159
  def load_cache(file_array)
189
160
  file_path = datafile_path(file_array)
190
161
  File.exist?(file_path) ? JSON.parse(File.binread(file_path)) : {}
@@ -192,9 +163,7 @@ module ISO3166
192
163
 
193
164
  def deep_stringify_keys(data)
194
165
  data.transform_keys!(&:to_s)
195
- data.transform_values! do |v|
196
- v.is_a?(Hash) ? deep_stringify_keys(v) : v
197
- end
166
+ data.transform_values! { |v| v.is_a?(Hash) ? deep_stringify_keys(v) : v }
198
167
 
199
168
  data
200
169
  end
@@ -15,5 +15,4 @@ require 'countries'
15
15
  # gem 'countries', require: 'countries/global'
16
16
  #
17
17
  class Country < ISO3166::Country
18
-
19
18
  end
@@ -4,9 +4,12 @@ require 'yaml'
4
4
  require 'json'
5
5
 
6
6
  require 'countries/configuration'
7
+ require 'countries/data/locales_methods'
8
+ require 'countries/data/subdivision_methods'
7
9
  require 'countries/data'
8
10
  require 'countries/structure'
9
11
  require 'countries/translations'
12
+ require 'countries/country/country_subdivision_methods'
10
13
  require 'countries/country/class_methods'
11
14
  require 'countries/country/finder_methods'
12
15
  require 'countries/country/emoji'
@@ -20,7 +20,7 @@ module Sources
20
20
  end
21
21
 
22
22
  def code
23
- type[2..-1].upcase
23
+ type[2..].upcase
24
24
  end
25
25
 
26
26
  def type
@@ -19,5 +19,10 @@ module ISO3166
19
19
  def [](attr_name)
20
20
  send attr_name
21
21
  end
22
+
23
+ # @return [Hash] A hash with the subdivision code as key and the hash of translated subdivision names ( locale => name ) as value.
24
+ def code_with_translations
25
+ { code => translations }
26
+ end
22
27
  end
23
28
  end
@@ -19,7 +19,11 @@ namespace :postal_codes do
19
19
  postal_code_format_index = data.find_index { |d| d[0] == 'postal_code_format' }
20
20
 
21
21
  response = URI.open("https://chromium-i18n.appspot.com/ssl-address/data/#{country_code}").read
22
- json = JSON.parse(response) rescue {}
22
+ json = begin
23
+ JSON.parse(response)
24
+ rescue StandardError
25
+ {}
26
+ end
23
27
  puts ' - Returned empty data. Skipping ' and next if json.empty?
24
28
 
25
29
  postal_code = ['postal_code', !json['zip'].nil?]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Countries
4
- VERSION = '5.4.0'.freeze
4
+ VERSION = '5.5.0'
5
5
  end
data/spec/country_spec.rb CHANGED
@@ -3,7 +3,11 @@
3
3
  require 'spec_helper'
4
4
  NUM_OF_COUNTRIES = 249
5
5
  describe ISO3166::Country do
6
- before { ISO3166.configuration.enable_currency_extension! }
6
+ before do
7
+ ISO3166::Data.reset
8
+ ISO3166.configuration.enable_currency_extension!
9
+ end
10
+
7
11
  let(:country) { ISO3166::Country.search('US') }
8
12
 
9
13
  it 'allows to create a country object from a symbol representation of the alpha2 code' do
@@ -48,11 +52,11 @@ describe ISO3166::Country do
48
52
  end
49
53
 
50
54
  it 'should return alternate names' do
51
- expect(country.unofficial_names).to eq(["United States", "USA",
52
- "Vereinigte Staaten von Amerika",
53
- "États-Unis", "Estados Unidos",
54
- "アメリカ合衆国", "Verenigde Staten",
55
- "Соединенные Штаты Америки"])
55
+ expect(country.unofficial_names).to eq(['United States', 'USA',
56
+ 'Vereinigte Staaten von Amerika',
57
+ 'États-Unis', 'Estados Unidos',
58
+ 'アメリカ合衆国', 'Verenigde Staten',
59
+ 'Соединенные Штаты Америки'])
56
60
  end
57
61
 
58
62
  it 'should return translations' do
@@ -149,7 +153,7 @@ describe ISO3166::Country do
149
153
  ISO3166::Data.register(
150
154
  alpha2: 'BR2',
151
155
  iso_short_name: 'Brazil',
152
- languages_official: %w(pt-BR),
156
+ languages_official: %w[pt-BR],
153
157
  translations: {
154
158
  'pt-BR' => 'Translation for pt-BR',
155
159
  'pt' => 'Translation for pt'
@@ -173,7 +177,7 @@ describe ISO3166::Country do
173
177
  ISO3166::Data.register(
174
178
  alpha2: 'BR2',
175
179
  iso_short_name: 'Brazil',
176
- languages_official: %w(pt-BR),
180
+ languages_official: %w[pt-BR],
177
181
  translations: {
178
182
  'pt' => 'Translation for pt'
179
183
  }
@@ -241,7 +245,7 @@ describe ISO3166::Country do
241
245
  end
242
246
 
243
247
  it '#states should be deprecated' do
244
- expect {country.states}.to output.to_stderr
248
+ expect { country.states }.to output.to_stderr
245
249
  end
246
250
 
247
251
  it 'should be a subdivision object' do
@@ -262,54 +266,54 @@ describe ISO3166::Country do
262
266
  end
263
267
 
264
268
  describe 'subdivision_types' do
265
- it "should return an array of subdivision types" do
269
+ it 'should return an array of subdivision types' do
266
270
  expect(country.subdivision_types).to contain_exactly('district', 'state', 'outlying_area')
267
271
  end
268
272
 
269
- it "should return an array of subdivision types even if there is only a single type" do
273
+ it 'should return an array of subdivision types even if there is only a single type' do
270
274
  expect(ISO3166::Country['LI'].subdivision_types).to contain_exactly('commune')
271
275
  end
272
276
 
273
- it "should return an empty array if country has no subdivisions" do
277
+ it 'should return an empty array if country has no subdivisions' do
274
278
  expect(ISO3166::Country['AS'].subdivisions?).to be_falsey
275
279
  expect(ISO3166::Country['AS'].subdivision_types).to eq([])
276
280
  end
277
281
  end
278
282
 
279
283
  describe 'subdivisions_of_types' do
280
- it "given a single type, should return an array of subdivisions that match the type" do
284
+ it 'given a single type, should return an array of subdivisions that match the type' do
281
285
  us_states = country.subdivisions_of_types(%w[state])
282
286
  expect(us_states.size).to eq(50)
283
287
  dc = country.subdivisions_of_types(%w[district])
284
288
  expect(dc.size).to eq(1)
285
289
  end
286
290
 
287
- it "given multiple types, should return an array of subdivisions matching the types" do
291
+ it 'given multiple types, should return an array of subdivisions matching the types' do
288
292
  us_states_plus_dc = country.subdivisions_of_types(%w[state district])
289
293
  expect(us_states_plus_dc.size).to eq(51)
290
294
  end
291
295
 
292
- it "given multiple types where at least one does not exist for that country, should work without issue" do
296
+ it 'given multiple types where at least one does not exist for that country, should work without issue' do
293
297
  us_states_plus_dc = country.subdivisions_of_types(%w[state district governorate])
294
298
  expect(us_states_plus_dc.size).to eq(51)
295
299
  end
296
300
 
297
- it "given only types that do not exist for that country, should return an empty collection" do
301
+ it 'given only types that do not exist for that country, should return an empty collection' do
298
302
  should_be_empty = ISO3166::Country['PT'].subdivisions_of_types(%w[state county])
299
303
  expect(should_be_empty).to be_empty
300
304
  end
301
305
  end
302
306
 
303
307
  describe 'humanized_subdivision_types' do
304
- it "should return an array of humanized subdivision types" do
308
+ it 'should return an array of humanized subdivision types' do
305
309
  expect(country.humanized_subdivision_types).to contain_exactly('District', 'State', 'Outlying area')
306
310
  end
307
311
 
308
- it "should return an array of subdivision types even if there is only a single type" do
312
+ it 'should return an array of subdivision types even if there is only a single type' do
309
313
  expect(ISO3166::Country['LI'].humanized_subdivision_types).to contain_exactly('Commune')
310
314
  end
311
315
 
312
- it "should return an empty array if country has no subdivisions" do
316
+ it 'should return an empty array if country has no subdivisions' do
313
317
  expect(ISO3166::Country['AS'].subdivisions?).to be_falsey
314
318
  expect(ISO3166::Country['AS'].humanized_subdivision_types).to eq([])
315
319
  end
@@ -878,7 +882,12 @@ describe ISO3166::Country do
878
882
  context 'regression test for #388/#746/#776' do
879
883
  before do
880
884
  ISO3166.configure do |config|
881
- 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]
885
+ config.locales = %i[af am ar as az be bg bn br bs ca cs cy da de dz el en
886
+ eo es et eu fa fi fo fr ga gl gu he hi hr hu hy ia id
887
+ is it ja ka kk km kn ko ku lt lv mi mk ml mn mr ms mt
888
+ nb ne nl nn oc or pa pl ps pt ro ru rw si sk sl so sq
889
+ sr sv sw ta te th ti tk tl tr tt ug uk ve vi wa wo xh
890
+ zh zu]
882
891
  end
883
892
  end
884
893
 
@@ -1071,6 +1080,24 @@ describe ISO3166::Country do
1071
1080
  end
1072
1081
  end
1073
1082
 
1083
+ describe 'gdpr_compliant?' do
1084
+ let(:united_kigndom) { ISO3166::Country.search('GB') }
1085
+ let(:france) { ISO3166::Country.search('FR') }
1086
+ let(:mexico) { ISO3166::Country.search('MX') }
1087
+
1088
+ it 'should return false for countries without eea_member flag' do
1089
+ expect(mexico.gdpr_compliant?).to be_falsey
1090
+ end
1091
+
1092
+ it 'should return true for countries with eea_member flag set to true' do
1093
+ expect(france.gdpr_compliant?).to be_truthy
1094
+ end
1095
+
1096
+ it 'should return true for UK' do
1097
+ expect(united_kigndom.gdpr_compliant?).to be_truthy
1098
+ end
1099
+ end
1100
+
1074
1101
  describe 'in_esm?' do
1075
1102
  let(:netherlands) { ISO3166::Country.search('NL') }
1076
1103
  let(:switzerland) { ISO3166::Country.search('CH') }
@@ -1214,13 +1241,82 @@ describe ISO3166::Country do
1214
1241
  expect(subject.last).to be_empty
1215
1242
  end
1216
1243
 
1217
- context "when asking for alpha2, alpha3 and iso_short_name" do
1218
- let(:args) { [:alpha2, :alpha3, :iso_short_name] }
1244
+ context 'when asking for alpha2, alpha3 and iso_short_name' do
1245
+ let(:args) { %i[alpha2 alpha3 iso_short_name] }
1219
1246
 
1220
1247
  it 'returns the correct values' do
1221
1248
  expect(subject.first).to eq(%w[AD AND Andorra])
1222
1249
  expect(subject.last).to eq(%w[ZW ZWE Zimbabwe])
1223
1250
  end
1224
1251
  end
1252
+
1253
+ context 'with invalid attributes' do
1254
+ let(:args) { %i[alpha2 bad_attribute] }
1255
+
1256
+ it 'should raise an error' do
1257
+ expect { subject }.to(
1258
+ raise_error(KeyError, 'key not found: "bad_attribute"')
1259
+ )
1260
+ end
1261
+ end
1262
+ end
1263
+
1264
+ describe 'find_subdivision_by_name' do
1265
+ let(:italy) { ISO3166::Country.new('IT') }
1266
+ let(:napoli) { italy.subdivisions['NA'] }
1267
+
1268
+ before do
1269
+ ISO3166.configuration.locales = %i[pt]
1270
+ end
1271
+
1272
+ it 'should find a subdivision using the official name' do
1273
+ expect(ISO3166::Country.new('IT').find_subdivision_by_name('Napoli')).to eq napoli
1274
+ end
1275
+
1276
+ it 'should find a subdivision using the code' do
1277
+ expect(ISO3166::Country.new('IT').find_subdivision_by_name('NA')).to eq napoli
1278
+ end
1279
+
1280
+ it 'should find a subdivision using a translated name' do
1281
+ expect(ISO3166::Country.new('IT').find_subdivision_by_name('Nápoles')).to eq napoli
1282
+ end
1283
+ end
1284
+
1285
+ describe 'collect_countries_with' do
1286
+ let(:italy) { ISO3166::Country.new('IT') }
1287
+ let(:vatican) { ISO3166::Country.new('VA') }
1288
+ let(:san_marino) { ISO3166::Country.new('SM') }
1289
+ let(:switzerland) { ISO3166::Country.new('CH') }
1290
+ let(:seychelles) { ISO3166::Country.new('SC') }
1291
+
1292
+ it 'defaults to querying alpha2 and returning the countries' do
1293
+ expect(ISO3166::Country.collect_countries_with('IT')).to eq [italy]
1294
+ end
1295
+
1296
+ it 'allows querying by other attributes' do
1297
+ expect(ISO3166::Country.collect_countries_with('🇸🇨', :emoji_flag)).to eq [seychelles]
1298
+ expect(ISO3166::Country.collect_countries_with('it',
1299
+ :languages_spoken)).to eq [switzerland, italy, san_marino, vatican]
1300
+ end
1301
+
1302
+ it 'allows applying a method to the result set' do
1303
+ expect(ISO3166::Country.collect_countries_with('Caribbean', :subregion,
1304
+ :languages_spoken).flatten.uniq).to eq %w[en nl fr es ht]
1305
+ end
1306
+ end
1307
+
1308
+ describe 'collect_likely_countries_by_subdivision_name' do
1309
+ let(:costa_rica) { ISO3166::Country.new('CR') }
1310
+ let(:uruguay) { ISO3166::Country.new('UY') }
1311
+
1312
+ it 'defaults to returning the countries' do
1313
+ expect(ISO3166::Country.collect_likely_countries_by_subdivision_name('San José')).to eq [costa_rica, uruguay]
1314
+ end
1315
+
1316
+ it 'allows applying a method to the result set' do
1317
+ expect(ISO3166::Country.collect_likely_countries_by_subdivision_name('San José',
1318
+ :iso_short_name)).to eq ['Costa Rica',
1319
+ 'Uruguay']
1320
+ end
1225
1321
  end
1226
1322
  end