countries 3.0.1 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (614) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +37 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +104 -1
  5. data/Gemfile +5 -0
  6. data/README.markdown +51 -35
  7. data/Rakefile +5 -3
  8. data/countries.gemspec +10 -5
  9. data/lib/countries/cache/countries.json +1 -1
  10. data/lib/countries/cache/locales/ab.json +1 -1
  11. data/lib/countries/cache/locales/af.json +1 -1
  12. data/lib/countries/cache/locales/ak.json +1 -1
  13. data/lib/countries/cache/locales/am.json +1 -1
  14. data/lib/countries/cache/locales/an.json +1 -1
  15. data/lib/countries/cache/locales/ar.json +1 -1
  16. data/lib/countries/cache/locales/as.json +1 -1
  17. data/lib/countries/cache/locales/ay.json +1 -1
  18. data/lib/countries/cache/locales/az.json +1 -1
  19. data/lib/countries/cache/locales/ba.json +1 -1
  20. data/lib/countries/cache/locales/be.json +1 -1
  21. data/lib/countries/cache/locales/bg.json +1 -1
  22. data/lib/countries/cache/locales/bi.json +1 -1
  23. data/lib/countries/cache/locales/bn-in.json +1 -1
  24. data/lib/countries/cache/locales/bn.json +1 -1
  25. data/lib/countries/cache/locales/br.json +1 -1
  26. data/lib/countries/cache/locales/bs.json +1 -1
  27. data/lib/countries/cache/locales/ca.json +1 -1
  28. data/lib/countries/cache/locales/ce.json +1 -1
  29. data/lib/countries/cache/locales/ch.json +1 -1
  30. data/lib/countries/cache/locales/cs.json +1 -1
  31. data/lib/countries/cache/locales/cv.json +1 -1
  32. data/lib/countries/cache/locales/cy.json +1 -1
  33. data/lib/countries/cache/locales/da.json +1 -1
  34. data/lib/countries/cache/locales/de.json +1 -1
  35. data/lib/countries/cache/locales/dv.json +1 -1
  36. data/lib/countries/cache/locales/dz.json +1 -1
  37. data/lib/countries/cache/locales/ee.json +1 -1
  38. data/lib/countries/cache/locales/el.json +1 -1
  39. data/lib/countries/cache/locales/en.json +1 -1
  40. data/lib/countries/cache/locales/eo.json +1 -1
  41. data/lib/countries/cache/locales/es.json +1 -1
  42. data/lib/countries/cache/locales/et.json +1 -1
  43. data/lib/countries/cache/locales/eu.json +1 -1
  44. data/lib/countries/cache/locales/fa.json +1 -1
  45. data/lib/countries/cache/locales/ff.json +1 -1
  46. data/lib/countries/cache/locales/fi.json +1 -1
  47. data/lib/countries/cache/locales/fo.json +1 -1
  48. data/lib/countries/cache/locales/fr.json +1 -1
  49. data/lib/countries/cache/locales/fy.json +1 -1
  50. data/lib/countries/cache/locales/ga.json +1 -1
  51. data/lib/countries/cache/locales/gl.json +1 -1
  52. data/lib/countries/cache/locales/gn.json +1 -1
  53. data/lib/countries/cache/locales/gu.json +1 -1
  54. data/lib/countries/cache/locales/gv.json +1 -1
  55. data/lib/countries/cache/locales/ha.json +1 -1
  56. data/lib/countries/cache/locales/he.json +1 -1
  57. data/lib/countries/cache/locales/hi.json +1 -1
  58. data/lib/countries/cache/locales/hr.json +1 -1
  59. data/lib/countries/cache/locales/ht.json +1 -1
  60. data/lib/countries/cache/locales/hu.json +1 -1
  61. data/lib/countries/cache/locales/hy.json +1 -1
  62. data/lib/countries/cache/locales/ia.json +1 -1
  63. data/lib/countries/cache/locales/id.json +1 -1
  64. data/lib/countries/cache/locales/io.json +1 -1
  65. data/lib/countries/cache/locales/is.json +1 -1
  66. data/lib/countries/cache/locales/it.json +1 -1
  67. data/lib/countries/cache/locales/iu.json +1 -1
  68. data/lib/countries/cache/locales/ja.json +1 -1
  69. data/lib/countries/cache/locales/ka.json +1 -1
  70. data/lib/countries/cache/locales/ki.json +1 -1
  71. data/lib/countries/cache/locales/kk.json +1 -1
  72. data/lib/countries/cache/locales/kl.json +1 -1
  73. data/lib/countries/cache/locales/km.json +1 -1
  74. data/lib/countries/cache/locales/kn.json +1 -1
  75. data/lib/countries/cache/locales/ko.json +1 -1
  76. data/lib/countries/cache/locales/ku.json +1 -1
  77. data/lib/countries/cache/locales/kv.json +1 -1
  78. data/lib/countries/cache/locales/kw.json +1 -1
  79. data/lib/countries/cache/locales/ky.json +1 -1
  80. data/lib/countries/cache/locales/lo.json +1 -1
  81. data/lib/countries/cache/locales/lt.json +1 -1
  82. data/lib/countries/cache/locales/lv.json +1 -1
  83. data/lib/countries/cache/locales/mi.json +1 -1
  84. data/lib/countries/cache/locales/mk.json +1 -1
  85. data/lib/countries/cache/locales/ml.json +1 -1
  86. data/lib/countries/cache/locales/mn.json +1 -1
  87. data/lib/countries/cache/locales/mr.json +1 -1
  88. data/lib/countries/cache/locales/ms.json +1 -1
  89. data/lib/countries/cache/locales/mt.json +1 -1
  90. data/lib/countries/cache/locales/my.json +1 -1
  91. data/lib/countries/cache/locales/na.json +1 -1
  92. data/lib/countries/cache/locales/nb.json +1 -1
  93. data/lib/countries/cache/locales/ne.json +1 -1
  94. data/lib/countries/cache/locales/nl.json +1 -1
  95. data/lib/countries/cache/locales/nn.json +1 -1
  96. data/lib/countries/cache/locales/nv.json +1 -1
  97. data/lib/countries/cache/locales/oc.json +1 -1
  98. data/lib/countries/cache/locales/or.json +1 -1
  99. data/lib/countries/cache/locales/pa.json +1 -1
  100. data/lib/countries/cache/locales/pi.json +1 -1
  101. data/lib/countries/cache/locales/pl.json +1 -1
  102. data/lib/countries/cache/locales/ps.json +1 -1
  103. data/lib/countries/cache/locales/pt-br.json +1 -1
  104. data/lib/countries/cache/locales/pt.json +1 -1
  105. data/lib/countries/cache/locales/ro.json +1 -1
  106. data/lib/countries/cache/locales/ru.json +1 -1
  107. data/lib/countries/cache/locales/rw.json +1 -1
  108. data/lib/countries/cache/locales/sc.json +1 -1
  109. data/lib/countries/cache/locales/sd.json +1 -1
  110. data/lib/countries/cache/locales/si.json +1 -1
  111. data/lib/countries/cache/locales/sk.json +1 -1
  112. data/lib/countries/cache/locales/sl.json +1 -1
  113. data/lib/countries/cache/locales/so.json +1 -1
  114. data/lib/countries/cache/locales/sq.json +1 -1
  115. data/lib/countries/cache/locales/sr.json +1 -1
  116. data/lib/countries/cache/locales/sv.json +1 -1
  117. data/lib/countries/cache/locales/sw.json +1 -1
  118. data/lib/countries/cache/locales/ta.json +1 -1
  119. data/lib/countries/cache/locales/te.json +1 -1
  120. data/lib/countries/cache/locales/tg.json +1 -1
  121. data/lib/countries/cache/locales/th.json +1 -1
  122. data/lib/countries/cache/locales/ti.json +1 -1
  123. data/lib/countries/cache/locales/tk.json +1 -1
  124. data/lib/countries/cache/locales/tl.json +1 -1
  125. data/lib/countries/cache/locales/tr.json +1 -1
  126. data/lib/countries/cache/locales/tt.json +1 -1
  127. data/lib/countries/cache/locales/ug.json +1 -1
  128. data/lib/countries/cache/locales/uk.json +1 -1
  129. data/lib/countries/cache/locales/ur.json +1 -1
  130. data/lib/countries/cache/locales/uz.json +1 -1
  131. data/lib/countries/cache/locales/ve.json +1 -1
  132. data/lib/countries/cache/locales/vi.json +1 -1
  133. data/lib/countries/cache/locales/wa.json +1 -1
  134. data/lib/countries/cache/locales/wo.json +1 -1
  135. data/lib/countries/cache/locales/xh.json +1 -1
  136. data/lib/countries/cache/locales/yo.json +1 -1
  137. data/lib/countries/cache/locales/zh-cn.json +1 -1
  138. data/lib/countries/cache/locales/zh-hk.json +1 -1
  139. data/lib/countries/cache/locales/zh-tw.json +1 -1
  140. data/lib/countries/cache/locales/zh.json +1 -1
  141. data/lib/countries/cache/locales/zu.json +1 -1
  142. data/lib/countries/country/class_methods.rb +18 -4
  143. data/lib/countries/country.rb +5 -0
  144. data/lib/countries/data/countries/AD.yaml +1 -0
  145. data/lib/countries/data/countries/AF.yaml +1 -0
  146. data/lib/countries/data/countries/AG.yaml +1 -1
  147. data/lib/countries/data/countries/AI.yaml +1 -0
  148. data/lib/countries/data/countries/AL.yaml +4 -3
  149. data/lib/countries/data/countries/AM.yaml +3 -2
  150. data/lib/countries/data/countries/AO.yaml +10 -10
  151. data/lib/countries/data/countries/AQ.yaml +3 -3
  152. data/lib/countries/data/countries/AR.yaml +1 -0
  153. data/lib/countries/data/countries/AS.yaml +3 -2
  154. data/lib/countries/data/countries/AT.yaml +4 -3
  155. data/lib/countries/data/countries/AU.yaml +1 -0
  156. data/lib/countries/data/countries/AX.yaml +1 -0
  157. data/lib/countries/data/countries/AZ.yaml +1 -0
  158. data/lib/countries/data/countries/BA.yaml +5 -4
  159. data/lib/countries/data/countries/BB.yaml +1 -0
  160. data/lib/countries/data/countries/BD.yaml +3 -2
  161. data/lib/countries/data/countries/BE.yaml +2 -1
  162. data/lib/countries/data/countries/BF.yaml +8 -8
  163. data/lib/countries/data/countries/BG.yaml +5 -4
  164. data/lib/countries/data/countries/BH.yaml +6 -5
  165. data/lib/countries/data/countries/BI.yaml +6 -6
  166. data/lib/countries/data/countries/BJ.yaml +2 -2
  167. data/lib/countries/data/countries/BL.yaml +1 -0
  168. data/lib/countries/data/countries/BM.yaml +1 -0
  169. data/lib/countries/data/countries/BN.yaml +2 -1
  170. data/lib/countries/data/countries/BO.yaml +1 -1
  171. data/lib/countries/data/countries/BQ.yaml +1 -1
  172. data/lib/countries/data/countries/BR.yaml +7 -6
  173. data/lib/countries/data/countries/BT.yaml +7 -6
  174. data/lib/countries/data/countries/BV.yaml +11 -11
  175. data/lib/countries/data/countries/BW.yaml +4 -4
  176. data/lib/countries/data/countries/BY.yaml +1 -0
  177. data/lib/countries/data/countries/BZ.yaml +1 -1
  178. data/lib/countries/data/countries/CA.yaml +1 -0
  179. data/lib/countries/data/countries/CC.yaml +3 -2
  180. data/lib/countries/data/countries/CF.yaml +2 -2
  181. data/lib/countries/data/countries/CG.yaml +2 -2
  182. data/lib/countries/data/countries/CH.yaml +4 -3
  183. data/lib/countries/data/countries/CI.yaml +2 -2
  184. data/lib/countries/data/countries/CL.yaml +8 -2
  185. data/lib/countries/data/countries/CN.yaml +5 -4
  186. data/lib/countries/data/countries/CO.yaml +5 -4
  187. data/lib/countries/data/countries/CR.yaml +3 -2
  188. data/lib/countries/data/countries/CU.yaml +1 -0
  189. data/lib/countries/data/countries/CV.yaml +3 -2
  190. data/lib/countries/data/countries/CW.yaml +1 -1
  191. data/lib/countries/data/countries/CX.yaml +1 -0
  192. data/lib/countries/data/countries/CY.yaml +3 -2
  193. data/lib/countries/data/countries/CZ.yaml +4 -3
  194. data/lib/countries/data/countries/DE.yaml +3 -2
  195. data/lib/countries/data/countries/DJ.yaml +6 -6
  196. data/lib/countries/data/countries/DK.yaml +3 -2
  197. data/lib/countries/data/countries/DO.yaml +1 -0
  198. data/lib/countries/data/countries/DZ.yaml +7 -6
  199. data/lib/countries/data/countries/EC.yaml +5 -4
  200. data/lib/countries/data/countries/EE.yaml +4 -3
  201. data/lib/countries/data/countries/EG.yaml +1 -0
  202. data/lib/countries/data/countries/EH.yaml +1 -0
  203. data/lib/countries/data/countries/ES.yaml +2 -1
  204. data/lib/countries/data/countries/ET.yaml +1 -0
  205. data/lib/countries/data/countries/FI.yaml +6 -5
  206. data/lib/countries/data/countries/FK.yaml +3 -2
  207. data/lib/countries/data/countries/FM.yaml +3 -2
  208. data/lib/countries/data/countries/FO.yaml +6 -5
  209. data/lib/countries/data/countries/FR.yaml +4 -3
  210. data/lib/countries/data/countries/GA.yaml +1 -1
  211. data/lib/countries/data/countries/GB.yaml +4 -0
  212. data/lib/countries/data/countries/GE.yaml +5 -4
  213. data/lib/countries/data/countries/GF.yaml +1 -0
  214. data/lib/countries/data/countries/GG.yaml +11 -10
  215. data/lib/countries/data/countries/GH.yaml +4 -4
  216. data/lib/countries/data/countries/GI.yaml +3 -2
  217. data/lib/countries/data/countries/GL.yaml +8 -7
  218. data/lib/countries/data/countries/GM.yaml +4 -4
  219. data/lib/countries/data/countries/GN.yaml +4 -3
  220. data/lib/countries/data/countries/GP.yaml +1 -0
  221. data/lib/countries/data/countries/GR.yaml +3 -2
  222. data/lib/countries/data/countries/GS.yaml +3 -2
  223. data/lib/countries/data/countries/GT.yaml +3 -2
  224. data/lib/countries/data/countries/GU.yaml +1 -0
  225. data/lib/countries/data/countries/GW.yaml +1 -0
  226. data/lib/countries/data/countries/HK.yaml +4 -4
  227. data/lib/countries/data/countries/HM.yaml +2 -1
  228. data/lib/countries/data/countries/HN.yaml +3 -2
  229. data/lib/countries/data/countries/HR.yaml +4 -3
  230. data/lib/countries/data/countries/HT.yaml +1 -0
  231. data/lib/countries/data/countries/HU.yaml +8 -7
  232. data/lib/countries/data/countries/ID.yaml +1 -0
  233. data/lib/countries/data/countries/IE.yaml +12 -11
  234. data/lib/countries/data/countries/IL.yaml +1 -0
  235. data/lib/countries/data/countries/IM.yaml +9 -8
  236. data/lib/countries/data/countries/IN.yaml +3 -2
  237. data/lib/countries/data/countries/IO.yaml +4 -3
  238. data/lib/countries/data/countries/IQ.yaml +3 -2
  239. data/lib/countries/data/countries/IR.yaml +1 -0
  240. data/lib/countries/data/countries/IS.yaml +6 -5
  241. data/lib/countries/data/countries/IT.yaml +2 -1
  242. data/lib/countries/data/countries/JE.yaml +1 -0
  243. data/lib/countries/data/countries/JO.yaml +3 -2
  244. data/lib/countries/data/countries/JP.yaml +1 -0
  245. data/lib/countries/data/countries/KE.yaml +4 -3
  246. data/lib/countries/data/countries/KG.yaml +3 -2
  247. data/lib/countries/data/countries/KH.yaml +1 -0
  248. data/lib/countries/data/countries/KI.yaml +6 -6
  249. data/lib/countries/data/countries/KP.yaml +3 -2
  250. data/lib/countries/data/countries/KR.yaml +1 -0
  251. data/lib/countries/data/countries/KW.yaml +1 -0
  252. data/lib/countries/data/countries/KY.yaml +1 -0
  253. data/lib/countries/data/countries/KZ.yaml +3 -2
  254. data/lib/countries/data/countries/LA.yaml +7 -6
  255. data/lib/countries/data/countries/LB.yaml +1 -0
  256. data/lib/countries/data/countries/LI.yaml +1 -0
  257. data/lib/countries/data/countries/LK.yaml +1 -0
  258. data/lib/countries/data/countries/LR.yaml +1 -0
  259. data/lib/countries/data/countries/LS.yaml +1 -0
  260. data/lib/countries/data/countries/LT.yaml +7 -6
  261. data/lib/countries/data/countries/LU.yaml +1 -0
  262. data/lib/countries/data/countries/LV.yaml +11 -4
  263. data/lib/countries/data/countries/LY.yaml +1 -1
  264. data/lib/countries/data/countries/MA.yaml +5 -4
  265. data/lib/countries/data/countries/MC.yaml +1 -0
  266. data/lib/countries/data/countries/MD.yaml +9 -8
  267. data/lib/countries/data/countries/ME.yaml +3 -2
  268. data/lib/countries/data/countries/MF.yaml +1 -0
  269. data/lib/countries/data/countries/MG.yaml +1 -0
  270. data/lib/countries/data/countries/MH.yaml +3 -2
  271. data/lib/countries/data/countries/MK.yaml +3 -2
  272. data/lib/countries/data/countries/ML.yaml +4 -4
  273. data/lib/countries/data/countries/MM.yaml +1 -0
  274. data/lib/countries/data/countries/MN.yaml +9 -8
  275. data/lib/countries/data/countries/MP.yaml +1 -0
  276. data/lib/countries/data/countries/MQ.yaml +1 -0
  277. data/lib/countries/data/countries/MR.yaml +2 -2
  278. data/lib/countries/data/countries/MT.yaml +3 -2
  279. data/lib/countries/data/countries/MU.yaml +2 -1
  280. data/lib/countries/data/countries/MV.yaml +3 -2
  281. data/lib/countries/data/countries/MW.yaml +2 -2
  282. data/lib/countries/data/countries/MX.yaml +5 -4
  283. data/lib/countries/data/countries/MY.yaml +3 -2
  284. data/lib/countries/data/countries/MZ.yaml +1 -0
  285. data/lib/countries/data/countries/NA.yaml +5 -4
  286. data/lib/countries/data/countries/NC.yaml +1 -0
  287. data/lib/countries/data/countries/NE.yaml +5 -4
  288. data/lib/countries/data/countries/NF.yaml +1 -0
  289. data/lib/countries/data/countries/NG.yaml +2 -1
  290. data/lib/countries/data/countries/NI.yaml +3 -2
  291. data/lib/countries/data/countries/NL.yaml +4 -3
  292. data/lib/countries/data/countries/NO.yaml +3 -2
  293. data/lib/countries/data/countries/NP.yaml +7 -6
  294. data/lib/countries/data/countries/NZ.yaml +3 -2
  295. data/lib/countries/data/countries/OM.yaml +3 -2
  296. data/lib/countries/data/countries/PA.yaml +2 -2
  297. data/lib/countries/data/countries/PE.yaml +5 -4
  298. data/lib/countries/data/countries/PF.yaml +5 -4
  299. data/lib/countries/data/countries/PG.yaml +1 -0
  300. data/lib/countries/data/countries/PH.yaml +5 -4
  301. data/lib/countries/data/countries/PK.yaml +5 -4
  302. data/lib/countries/data/countries/PL.yaml +5 -4
  303. data/lib/countries/data/countries/PM.yaml +1 -0
  304. data/lib/countries/data/countries/PN.yaml +1 -0
  305. data/lib/countries/data/countries/PR.yaml +9 -8
  306. data/lib/countries/data/countries/PS.yaml +1 -1
  307. data/lib/countries/data/countries/PT.yaml +6 -5
  308. data/lib/countries/data/countries/PW.yaml +1 -0
  309. data/lib/countries/data/countries/PY.yaml +3 -2
  310. data/lib/countries/data/countries/QA.yaml +2 -2
  311. data/lib/countries/data/countries/RE.yaml +1 -0
  312. data/lib/countries/data/countries/RO.yaml +7 -6
  313. data/lib/countries/data/countries/RS.yaml +1 -0
  314. data/lib/countries/data/countries/RU.yaml +3 -2
  315. data/lib/countries/data/countries/RW.yaml +2 -2
  316. data/lib/countries/data/countries/SA.yaml +4 -3
  317. data/lib/countries/data/countries/SB.yaml +1 -1
  318. data/lib/countries/data/countries/SC.yaml +2 -2
  319. data/lib/countries/data/countries/SD.yaml +3 -2
  320. data/lib/countries/data/countries/SE.yaml +5 -4
  321. data/lib/countries/data/countries/SG.yaml +1 -0
  322. data/lib/countries/data/countries/SH.yaml +5 -4
  323. data/lib/countries/data/countries/SI.yaml +5 -4
  324. data/lib/countries/data/countries/SJ.yaml +6 -5
  325. data/lib/countries/data/countries/SK.yaml +7 -6
  326. data/lib/countries/data/countries/SL.yaml +2 -2
  327. data/lib/countries/data/countries/SM.yaml +1 -0
  328. data/lib/countries/data/countries/SN.yaml +5 -4
  329. data/lib/countries/data/countries/SO.yaml +2 -1
  330. data/lib/countries/data/countries/SS.yaml +2 -2
  331. data/lib/countries/data/countries/SV.yaml +1 -0
  332. data/lib/countries/data/countries/SX.yaml +1 -1
  333. data/lib/countries/data/countries/SZ.yaml +1 -0
  334. data/lib/countries/data/countries/TC.yaml +1 -0
  335. data/lib/countries/data/countries/TD.yaml +1 -1
  336. data/lib/countries/data/countries/TF.yaml +5 -5
  337. data/lib/countries/data/countries/TG.yaml +7 -7
  338. data/lib/countries/data/countries/TH.yaml +3 -1
  339. data/lib/countries/data/countries/TJ.yaml +1 -0
  340. data/lib/countries/data/countries/TM.yaml +1 -0
  341. data/lib/countries/data/countries/TN.yaml +1 -0
  342. data/lib/countries/data/countries/TR.yaml +1 -0
  343. data/lib/countries/data/countries/TV.yaml +3 -3
  344. data/lib/countries/data/countries/TW.yaml +1 -0
  345. data/lib/countries/data/countries/TZ.yaml +4 -3
  346. data/lib/countries/data/countries/UA.yaml +7 -6
  347. data/lib/countries/data/countries/UG.yaml +4 -4
  348. data/lib/countries/data/countries/UM.yaml +1 -0
  349. data/lib/countries/data/countries/US.yaml +1 -0
  350. data/lib/countries/data/countries/UY.yaml +3 -2
  351. data/lib/countries/data/countries/UZ.yaml +1 -0
  352. data/lib/countries/data/countries/VA.yaml +1 -0
  353. data/lib/countries/data/countries/VC.yaml +3 -2
  354. data/lib/countries/data/countries/VE.yaml +3 -2
  355. data/lib/countries/data/countries/VG.yaml +2 -1
  356. data/lib/countries/data/countries/VI.yaml +1 -0
  357. data/lib/countries/data/countries/VN.yaml +11 -4
  358. data/lib/countries/data/countries/WF.yaml +1 -0
  359. data/lib/countries/data/countries/WS.yaml +3 -3
  360. data/lib/countries/data/countries/YT.yaml +1 -0
  361. data/lib/countries/data/countries/ZA.yaml +5 -4
  362. data/lib/countries/data/countries/ZM.yaml +5 -4
  363. data/lib/countries/data/countries/ZW.yaml +4 -4
  364. data/lib/countries/data/subdivisions/AD.yaml +35 -28
  365. data/lib/countries/data/subdivisions/AE.yaml +154 -63
  366. data/lib/countries/data/subdivisions/AF.yaml +605 -300
  367. data/lib/countries/data/subdivisions/AG.yaml +149 -67
  368. data/lib/countries/data/subdivisions/AI.yaml +139 -125
  369. data/lib/countries/data/subdivisions/AL.yaml +472 -144
  370. data/lib/countries/data/subdivisions/AM.yaml +236 -88
  371. data/lib/countries/data/subdivisions/AO.yaml +344 -144
  372. data/lib/countries/data/subdivisions/AR.yaml +450 -187
  373. data/lib/countries/data/subdivisions/AS.yaml +34 -15
  374. data/lib/countries/data/subdivisions/AT.yaml +202 -72
  375. data/lib/countries/data/subdivisions/AU.yaml +212 -64
  376. data/lib/countries/data/subdivisions/AW.yaml +9 -0
  377. data/lib/countries/data/subdivisions/AX.yaml +20 -9
  378. data/lib/countries/data/subdivisions/AZ.yaml +1550 -592
  379. data/lib/countries/data/subdivisions/BA.yaml +189 -16
  380. data/lib/countries/data/subdivisions/BB.yaml +190 -88
  381. data/lib/countries/data/subdivisions/BD.yaml +1192 -519
  382. data/lib/countries/data/subdivisions/BE.yaml +278 -88
  383. data/lib/countries/data/subdivisions/BF.yaml +993 -366
  384. data/lib/countries/data/subdivisions/BG.yaml +600 -219
  385. data/lib/countries/data/subdivisions/BH.yaml +72 -35
  386. data/lib/countries/data/subdivisions/BI.yaml +298 -123
  387. data/lib/countries/data/subdivisions/BJ.yaml +226 -96
  388. data/lib/countries/data/subdivisions/BL.yaml +11 -0
  389. data/lib/countries/data/subdivisions/BM.yaml +110 -99
  390. data/lib/countries/data/subdivisions/BN.yaml +63 -32
  391. data/lib/countries/data/subdivisions/BO.yaml +157 -72
  392. data/lib/countries/data/subdivisions/BQ.yaml +63 -24
  393. data/lib/countries/data/subdivisions/BR.yaml +689 -216
  394. data/lib/countries/data/subdivisions/BS.yaml +625 -108
  395. data/lib/countries/data/subdivisions/BT.yaml +346 -160
  396. data/lib/countries/data/subdivisions/BW.yaml +294 -72
  397. data/lib/countries/data/subdivisions/BY.yaml +140 -51
  398. data/lib/countries/data/subdivisions/BZ.yaml +97 -48
  399. data/lib/countries/data/subdivisions/CA.yaml +358 -105
  400. data/lib/countries/data/subdivisions/CD.yaml +451 -68
  401. data/lib/countries/data/subdivisions/CF.yaml +291 -136
  402. data/lib/countries/data/subdivisions/CG.yaml +217 -88
  403. data/lib/countries/data/subdivisions/CH.yaml +593 -208
  404. data/lib/countries/data/subdivisions/CI.yaml +431 -66
  405. data/lib/countries/data/subdivisions/CK.yaml +110 -99
  406. data/lib/countries/data/subdivisions/CL.yaml +262 -132
  407. data/lib/countries/data/subdivisions/CM.yaml +190 -80
  408. data/lib/countries/data/subdivisions/CN.yaml +725 -46
  409. data/lib/countries/data/subdivisions/CO.yaml +643 -264
  410. data/lib/countries/data/subdivisions/CP.yaml +4 -0
  411. data/lib/countries/data/subdivisions/CR.yaml +119 -56
  412. data/lib/countries/data/subdivisions/CU.yaml +268 -128
  413. data/lib/countries/data/subdivisions/CV.yaml +414 -126
  414. data/lib/countries/data/subdivisions/CW.yaml +9 -0
  415. data/lib/countries/data/subdivisions/CY.yaml +102 -48
  416. data/lib/countries/data/subdivisions/CZ.yaml +2430 -53
  417. data/lib/countries/data/subdivisions/DE.yaml +468 -128
  418. data/lib/countries/data/subdivisions/DJ.yaml +110 -48
  419. data/lib/countries/data/subdivisions/DK.yaml +186 -96
  420. data/lib/countries/data/subdivisions/DM.yaml +159 -80
  421. data/lib/countries/data/subdivisions/DO.yaml +660 -248
  422. data/lib/countries/data/subdivisions/DZ.yaml +809 -384
  423. data/lib/countries/data/subdivisions/EC.yaml +391 -192
  424. data/lib/countries/data/subdivisions/EE.yaml +543 -120
  425. data/lib/countries/data/subdivisions/EG.yaml +472 -216
  426. data/lib/countries/data/subdivisions/EH.yaml +24 -16
  427. data/lib/countries/data/subdivisions/ER.yaml +109 -48
  428. data/lib/countries/data/subdivisions/ES.yaml +1740 -437
  429. data/lib/countries/data/subdivisions/ET.yaml +207 -88
  430. data/lib/countries/data/subdivisions/FI.yaml +421 -37
  431. data/lib/countries/data/subdivisions/FJ.yaml +314 -40
  432. data/lib/countries/data/subdivisions/FM.yaml +63 -32
  433. data/lib/countries/data/subdivisions/FO.yaml +60 -54
  434. data/lib/countries/data/subdivisions/FR.yaml +2861 -922
  435. data/lib/countries/data/subdivisions/GA.yaml +159 -72
  436. data/lib/countries/data/subdivisions/GB.yaml +4979 -1771
  437. data/lib/countries/data/subdivisions/GD.yaml +114 -56
  438. data/lib/countries/data/subdivisions/GE.yaml +238 -96
  439. data/lib/countries/data/subdivisions/GF.yaml +11 -0
  440. data/lib/countries/data/subdivisions/GG.yaml +110 -99
  441. data/lib/countries/data/subdivisions/GH.yaml +266 -79
  442. data/lib/countries/data/subdivisions/GL.yaml +89 -0
  443. data/lib/countries/data/subdivisions/GM.yaml +124 -48
  444. data/lib/countries/data/subdivisions/GN.yaml +711 -274
  445. data/lib/countries/data/subdivisions/GP.yaml +11 -0
  446. data/lib/countries/data/subdivisions/GQ.yaml +143 -72
  447. data/lib/countries/data/subdivisions/GR.yaml +594 -165
  448. data/lib/countries/data/subdivisions/GT.yaml +351 -176
  449. data/lib/countries/data/subdivisions/GU.yaml +85 -58
  450. data/lib/countries/data/subdivisions/GW.yaml +192 -72
  451. data/lib/countries/data/subdivisions/GY.yaml +163 -80
  452. data/lib/countries/data/subdivisions/HK.yaml +86 -54
  453. data/lib/countries/data/subdivisions/HN.yaml +274 -144
  454. data/lib/countries/data/subdivisions/HR.yaml +429 -168
  455. data/lib/countries/data/subdivisions/HT.yaml +179 -72
  456. data/lib/countries/data/subdivisions/HU.yaml +791 -339
  457. data/lib/countries/data/subdivisions/IC.yaml +4 -0
  458. data/lib/countries/data/subdivisions/ID.yaml +2376 -1858
  459. data/lib/countries/data/subdivisions/IE.yaml +650 -259
  460. data/lib/countries/data/subdivisions/IL.yaml +114 -48
  461. data/lib/countries/data/subdivisions/IM.yaml +240 -216
  462. data/lib/countries/data/subdivisions/IN.yaml +1005 -298
  463. data/lib/countries/data/subdivisions/IQ.yaml +316 -139
  464. data/lib/countries/data/subdivisions/IR.yaml +596 -239
  465. data/lib/countries/data/subdivisions/IS.yaml +373 -67
  466. data/lib/countries/data/subdivisions/IT.yaml +2693 -880
  467. data/lib/countries/data/subdivisions/JE.yaml +120 -108
  468. data/lib/countries/data/subdivisions/JM.yaml +243 -112
  469. data/lib/countries/data/subdivisions/JO.yaml +193 -96
  470. data/lib/countries/data/subdivisions/JP.yaml +950 -376
  471. data/lib/countries/data/subdivisions/KE.yaml +807 -40
  472. data/lib/countries/data/subdivisions/KG.yaml +188 -64
  473. data/lib/countries/data/subdivisions/KH.yaml +437 -192
  474. data/lib/countries/data/subdivisions/KI.yaml +57 -24
  475. data/lib/countries/data/subdivisions/KM.yaml +49 -24
  476. data/lib/countries/data/subdivisions/KN.yaml +308 -112
  477. data/lib/countries/data/subdivisions/KP.yaml +365 -57
  478. data/lib/countries/data/subdivisions/KR.yaml +393 -128
  479. data/lib/countries/data/subdivisions/KW.yaml +87 -48
  480. data/lib/countries/data/subdivisions/KY.yaml +36 -24
  481. data/lib/countries/data/subdivisions/KZ.yaml +362 -135
  482. data/lib/countries/data/subdivisions/LA.yaml +300 -145
  483. data/lib/countries/data/subdivisions/LB.yaml +134 -48
  484. data/lib/countries/data/subdivisions/LC.yaml +166 -0
  485. data/lib/countries/data/subdivisions/LI.yaml +186 -88
  486. data/lib/countries/data/subdivisions/LK.yaml +544 -200
  487. data/lib/countries/data/subdivisions/LR.yaml +252 -110
  488. data/lib/countries/data/subdivisions/LS.yaml +149 -80
  489. data/lib/countries/data/subdivisions/LT.yaml +1042 -80
  490. data/lib/countries/data/subdivisions/LU.yaml +200 -17
  491. data/lib/countries/data/subdivisions/LV.yaml +2399 -223
  492. data/lib/countries/data/subdivisions/LY.yaml +339 -162
  493. data/lib/countries/data/subdivisions/MA.yaml +1443 -484
  494. data/lib/countries/data/subdivisions/MC.yaml +250 -0
  495. data/lib/countries/data/subdivisions/MD.yaml +638 -93
  496. data/lib/countries/data/subdivisions/ME.yaml +425 -168
  497. data/lib/countries/data/subdivisions/MF.yaml +9 -0
  498. data/lib/countries/data/subdivisions/MG.yaml +93 -48
  499. data/lib/countries/data/subdivisions/MH.yaml +422 -199
  500. data/lib/countries/data/subdivisions/MK.yaml +2972 -255
  501. data/lib/countries/data/subdivisions/ML.yaml +187 -71
  502. data/lib/countries/data/subdivisions/MM.yaml +287 -112
  503. data/lib/countries/data/subdivisions/MN.yaml +421 -176
  504. data/lib/countries/data/subdivisions/MO.yaml +9 -0
  505. data/lib/countries/data/subdivisions/MP.yaml +30 -12
  506. data/lib/countries/data/subdivisions/MQ.yaml +11 -0
  507. data/lib/countries/data/subdivisions/MR.yaml +245 -99
  508. data/lib/countries/data/subdivisions/MS.yaml +30 -27
  509. data/lib/countries/data/subdivisions/MT.yaml +1059 -544
  510. data/lib/countries/data/subdivisions/MU.yaml +317 -131
  511. data/lib/countries/data/subdivisions/MV.yaml +457 -163
  512. data/lib/countries/data/subdivisions/MW.yaml +537 -216
  513. data/lib/countries/data/subdivisions/MX.yaml +709 -256
  514. data/lib/countries/data/subdivisions/MY.yaml +336 -128
  515. data/lib/countries/data/subdivisions/MZ.yaml +191 -83
  516. data/lib/countries/data/subdivisions/NA.yaml +220 -107
  517. data/lib/countries/data/subdivisions/NC.yaml +26 -9
  518. data/lib/countries/data/subdivisions/NE.yaml +170 -64
  519. data/lib/countries/data/subdivisions/NG.yaml +870 -296
  520. data/lib/countries/data/subdivisions/NI.yaml +260 -136
  521. data/lib/countries/data/subdivisions/NL.yaml +381 -96
  522. data/lib/countries/data/subdivisions/NO.yaml +1087 -268
  523. data/lib/countries/data/subdivisions/NP.yaml +383 -112
  524. data/lib/countries/data/subdivisions/NR.yaml +260 -112
  525. data/lib/countries/data/subdivisions/NZ.yaml +318 -131
  526. data/lib/countries/data/subdivisions/OM.yaml +202 -52
  527. data/lib/countries/data/subdivisions/PA.yaml +203 -99
  528. data/lib/countries/data/subdivisions/PE.yaml +418 -208
  529. data/lib/countries/data/subdivisions/PF.yaml +30 -15
  530. data/lib/countries/data/subdivisions/PG.yaml +381 -155
  531. data/lib/countries/data/subdivisions/PH.yaml +1855 -662
  532. data/lib/countries/data/subdivisions/PK.yaml +185 -54
  533. data/lib/countries/data/subdivisions/PL.yaml +1176 -127
  534. data/lib/countries/data/subdivisions/PM.yaml +18 -6
  535. data/lib/countries/data/subdivisions/PR.yaml +326 -234
  536. data/lib/countries/data/subdivisions/PS.yaml +257 -0
  537. data/lib/countries/data/subdivisions/PT.yaml +342 -160
  538. data/lib/countries/data/subdivisions/PW.yaml +269 -128
  539. data/lib/countries/data/subdivisions/PY.yaml +321 -144
  540. data/lib/countries/data/subdivisions/QA.yaml +168 -65
  541. data/lib/countries/data/subdivisions/RE.yaml +11 -0
  542. data/lib/countries/data/subdivisions/RO.yaml +729 -336
  543. data/lib/countries/data/subdivisions/RS.yaml +589 -240
  544. data/lib/countries/data/subdivisions/RU.yaml +1875 -665
  545. data/lib/countries/data/subdivisions/RW.yaml +102 -40
  546. data/lib/countries/data/subdivisions/SA.yaml +234 -104
  547. data/lib/countries/data/subdivisions/SB.yaml +169 -80
  548. data/lib/countries/data/subdivisions/SC.yaml +462 -184
  549. data/lib/countries/data/subdivisions/SD.yaml +163 -22
  550. data/lib/countries/data/subdivisions/SE.yaml +435 -237
  551. data/lib/countries/data/subdivisions/SG.yaml +111 -19
  552. data/lib/countries/data/subdivisions/SH.yaml +67 -14
  553. data/lib/countries/data/subdivisions/SI.yaml +3570 -1549
  554. data/lib/countries/data/subdivisions/SJ.yaml +20 -18
  555. data/lib/countries/data/subdivisions/SK.yaml +129 -64
  556. data/lib/countries/data/subdivisions/SL.yaml +80 -31
  557. data/lib/countries/data/subdivisions/SM.yaml +159 -72
  558. data/lib/countries/data/subdivisions/SN.yaml +233 -88
  559. data/lib/countries/data/subdivisions/SO.yaml +311 -144
  560. data/lib/countries/data/subdivisions/SR.yaml +158 -80
  561. data/lib/countries/data/subdivisions/SS.yaml +196 -0
  562. data/lib/countries/data/subdivisions/ST.yaml +49 -16
  563. data/lib/countries/data/subdivisions/SV.yaml +231 -112
  564. data/lib/countries/data/subdivisions/SX.yaml +9 -0
  565. data/lib/countries/data/subdivisions/SY.yaml +220 -112
  566. data/lib/countries/data/subdivisions/SZ.yaml +65 -32
  567. data/lib/countries/data/subdivisions/TA.yaml +4 -0
  568. data/lib/countries/data/subdivisions/TD.yaml +409 -139
  569. data/lib/countries/data/subdivisions/TF.yaml +38 -20
  570. data/lib/countries/data/subdivisions/TG.yaml +75 -40
  571. data/lib/countries/data/subdivisions/TH.yaml +1451 -616
  572. data/lib/countries/data/subdivisions/TJ.yaml +100 -24
  573. data/lib/countries/data/subdivisions/TK.yaml +30 -27
  574. data/lib/countries/data/subdivisions/TL.yaml +209 -104
  575. data/lib/countries/data/subdivisions/TM.yaml +116 -40
  576. data/lib/countries/data/subdivisions/TN.yaml +412 -192
  577. data/lib/countries/data/subdivisions/TO.yaml +75 -40
  578. data/lib/countries/data/subdivisions/TR.yaml +1817 -648
  579. data/lib/countries/data/subdivisions/TT.yaml +296 -113
  580. data/lib/countries/data/subdivisions/TV.yaml +133 -59
  581. data/lib/countries/data/subdivisions/TW.yaml +481 -164
  582. data/lib/countries/data/subdivisions/TZ.yaml +661 -208
  583. data/lib/countries/data/subdivisions/UA.yaml +505 -216
  584. data/lib/countries/data/subdivisions/UG.yaml +2262 -640
  585. data/lib/countries/data/subdivisions/UM.yaml +216 -71
  586. data/lib/countries/data/subdivisions/US.yaml +1658 -464
  587. data/lib/countries/data/subdivisions/UY.yaml +367 -152
  588. data/lib/countries/data/subdivisions/UZ.yaml +289 -113
  589. data/lib/countries/data/subdivisions/VC.yaml +101 -48
  590. data/lib/countries/data/subdivisions/VE.yaml +456 -200
  591. data/lib/countries/data/subdivisions/VI.yaml +26 -9
  592. data/lib/countries/data/subdivisions/VN.yaml +3664 -2996
  593. data/lib/countries/data/subdivisions/VU.yaml +98 -48
  594. data/lib/countries/data/subdivisions/WF.yaml +73 -0
  595. data/lib/countries/data/subdivisions/WS.yaml +200 -88
  596. data/lib/countries/data/subdivisions/YE.yaml +375 -152
  597. data/lib/countries/data/subdivisions/YT.yaml +76 -51
  598. data/lib/countries/data/subdivisions/ZA.yaml +238 -72
  599. data/lib/countries/data/subdivisions/ZM.yaml +157 -72
  600. data/lib/countries/data/subdivisions/ZW.yaml +152 -73
  601. data/lib/countries/data/translation_corrections.yaml +10 -1
  602. data/lib/countries/data.rb +47 -18
  603. data/lib/countries/sources/cldr/downloader.rb +12 -13
  604. data/lib/countries/structure.rb +1 -0
  605. data/lib/countries/tasks/geocoding.rake +9 -16
  606. data/lib/countries/tasks/postal_codes.rake +48 -0
  607. data/lib/countries/translations.rb +1 -1
  608. data/lib/countries/version.rb +1 -1
  609. data/lib/countries.rb +0 -1
  610. data/spec/country_spec.rb +73 -2
  611. data/spec/data_spec.rb +4 -4
  612. data/spec/thread_safety_spec.rb +46 -0
  613. metadata +34 -26
  614. data/.travis.yml +0 -15
@@ -5,6 +5,7 @@ module ISO3166
5
5
  @@cache_dir = [File.dirname(__FILE__), 'cache']
6
6
  @@cache = {}
7
7
  @@registered_data = {}
8
+ @@mutex = Mutex.new
8
9
 
9
10
  def initialize(alpha2)
10
11
  @alpha2 = alpha2.to_s.upcase
@@ -25,10 +26,9 @@ module ISO3166
25
26
 
26
27
  def register(data)
27
28
  alpha2 = data[:alpha2].upcase
28
- @@registered_data[alpha2] = \
29
- data.each_with_object({}) { |(k, v), a| a[k.to_s] = v }
29
+ @@registered_data[alpha2] = deep_stringify_keys(data)
30
30
  @@registered_data[alpha2]['translations'] = \
31
- Translations.new.merge(data[:translations] || {})
31
+ Translations.new.merge(data['translations'] || {})
32
32
  @@cache = cache.merge(@@registered_data)
33
33
  end
34
34
 
@@ -61,10 +61,12 @@ module ISO3166
61
61
 
62
62
  def load_data!
63
63
  return @@cache unless load_required?
64
- @@cache = load_cache %w(countries.json)
65
- @@_country_codes = @@cache.keys
66
- @@cache = @@cache.merge(@@registered_data)
67
- @@cache
64
+ synchronized do
65
+ @@cache = load_cache %w(countries.json)
66
+ @@_country_codes = @@cache.keys
67
+ @@cache = @@cache.merge(@@registered_data)
68
+ @@cache
69
+ end
68
70
  end
69
71
 
70
72
  def sync_translations!
@@ -81,8 +83,23 @@ module ISO3166
81
83
 
82
84
  private
83
85
 
86
+ def synchronized(&block)
87
+ if use_mutex?
88
+ @@mutex.synchronize(&block)
89
+ else
90
+ block.call
91
+ end
92
+ end
93
+
94
+ def use_mutex?
95
+ # Stubbed in testing
96
+ true
97
+ end
98
+
84
99
  def load_required?
85
- @@cache.empty?
100
+ synchronized do
101
+ @@cache.empty?
102
+ end
86
103
  end
87
104
 
88
105
  def loaded_codes
@@ -115,21 +132,25 @@ module ISO3166
115
132
  end
116
133
 
117
134
  def load_translations(locale)
118
- locale_names = load_cache(['locales', "#{locale}.json"])
119
- internal_codes.each do |alpha2|
120
- @@cache[alpha2]['translations'] ||= Translations.new
121
- @@cache[alpha2]['translations'][locale] = locale_names[alpha2].freeze
122
- @@cache[alpha2]['translated_names'] = @@cache[alpha2]['translations'].values.freeze
135
+ synchronized do
136
+ locale_names = load_cache(['locales', "#{locale}.json"])
137
+ internal_codes.each do |alpha2|
138
+ @@cache[alpha2]['translations'] ||= Translations.new
139
+ @@cache[alpha2]['translations'][locale] = locale_names[alpha2].freeze
140
+ @@cache[alpha2]['translated_names'] = @@cache[alpha2]['translations'].values.freeze
141
+ end
142
+ ISO3166.configuration.loaded_locales << locale
123
143
  end
124
- ISO3166.configuration.loaded_locales << locale
125
144
  end
126
145
 
127
146
  def unload_translations(locale)
128
- internal_codes.each do |alpha2|
129
- @@cache[alpha2]['translations'].delete(locale)
130
- @@cache[alpha2]['translated_names'] = @@cache[alpha2]['translations'].values.freeze
147
+ synchronized do
148
+ internal_codes.each do |alpha2|
149
+ @@cache[alpha2]['translations'].delete(locale)
150
+ @@cache[alpha2]['translated_names'] = @@cache[alpha2]['translations'].values.freeze
151
+ end
152
+ ISO3166.configuration.loaded_locales.delete(locale)
131
153
  end
132
- ISO3166.configuration.loaded_locales.delete(locale)
133
154
  end
134
155
 
135
156
  def load_cache(file_array)
@@ -140,6 +161,14 @@ module ISO3166
140
161
  def datafile_path(file_array)
141
162
  File.join([@@cache_dir] + file_array)
142
163
  end
164
+
165
+ def deep_stringify_keys(data)
166
+ data.transform_keys!(&:to_s)
167
+ data.transform_values! do |v|
168
+ v.is_a?(Hash) ? deep_stringify_keys(v) : v
169
+ end
170
+ return data
171
+ end
143
172
  end
144
173
  end
145
174
  end
@@ -2,6 +2,8 @@ require 'uri'
2
2
  require 'net/http'
3
3
  require 'nokogiri'
4
4
  require 'fileutils'
5
+ require 'json'
6
+
5
7
  module Sources
6
8
  module CLDR
7
9
  module Downloader
@@ -14,22 +16,19 @@ module Sources
14
16
  def download_folder(type)
15
17
  folder = File.join(ISO3166_ROOT_PATH, 'tmp', 'cldr', 'trunk', 'common', type)
16
18
  FileUtils.mkdir_p(folder)
17
- doc = Nokogiri::HTML get(type + '/')
18
- doc.css('a[href]').map { |e| e.attributes['href'].value }.each do |href|
19
- next if href == '../'
20
- File.write(File.join(folder, href), get([type, href].join('/')))
19
+ url = URI.parse("https://api.github.com/repos/unicode-org/cldr/contents/common/" + type)
20
+ path_listing = JSON.parse(Net::HTTP.get_response(url).body)
21
+ path_listing.each do |path|
22
+ if path['name'] =~ /\.xml$/
23
+ File.open(File.join(folder, path['name']), 'w') do |f|
24
+ raw_url = URI.parse(path['download_url'])
25
+ f.write(Net::HTTP.get_response(raw_url).body)
26
+ end
27
+ end
21
28
  end
22
29
  end
23
30
 
24
- def get(path)
25
- url = URI("http://www.unicode.org/repos/cldr/trunk/common/#{path}")
26
-
27
- http = Net::HTTP.new(url.host, url.port)
28
-
29
- request = Net::HTTP::Get.new(url)
30
- response = http.request(request)
31
- response.read_body
32
- end
33
31
  end
34
32
  end
35
33
  end
34
+
@@ -42,6 +42,7 @@ module ISO3166
42
42
  'languages_spoken' => [],
43
43
  'translations' => {},
44
44
  'postal_code' => nil,
45
+ 'postal_code_format' => nil,
45
46
  'region' => nil,
46
47
  'unofficial_names' => [],
47
48
  'start_of_week' => 'monday',
@@ -2,7 +2,9 @@ require 'geocoder'
2
2
  require 'retryable'
3
3
 
4
4
  Geocoder.configure(
5
- timeout: 10
5
+ lookup: :google,
6
+ timeout: 10,
7
+ api_key: GOOGLE_API_KEY
6
8
  )
7
9
 
8
10
  # raise on geocoding errors such as query limit exceeded
@@ -10,9 +12,9 @@ Geocoder.configure(always_raise: :all)
10
12
  # Try to geocode a given query, on exceptions it retries up to 3 times then gives up.
11
13
  # @param [String] query string to geocode
12
14
  # @return [Hash] first valid result or nil
13
- def geocode(query)
15
+ def geocode(query, params)
14
16
  Retryable.retryable(tries: 3, sleep: ->(n) { 2**n }) do
15
- Geocoder.search(query).first
17
+ Geocoder.search(query, params: params).first
16
18
  end
17
19
  rescue => e
18
20
  warn "Attempts exceeded for query #{query}, last error was #{e.message}"
@@ -41,12 +43,8 @@ namespace :geocode do
41
43
  # Load unmutated yaml file.
42
44
  data = load_country_yaml(country.alpha2)
43
45
 
44
- lookup = "#{country.alpha2} country"
45
- # LU country lookup appears to match to Los Angeles
46
- lookup = country.name if country.alpha2 == 'LU'
47
-
48
- next unless (result = geocode(lookup))
49
- puts 'WARNING:: Geocoder returned something that was not a country' unless result.types.include?('country')
46
+ next unless (result = geocode(country.name, {region: country.alpha2}))
47
+ puts "WARNING:: Geocoder returned something that was not a country for #{country.alpha2}" unless result.types.include?('country')
50
48
  geometry = result.geometry
51
49
 
52
50
  # Extract center point data
@@ -76,15 +74,10 @@ namespace :geocode do
76
74
  # Iterate subdivisions
77
75
  state_data = c.subdivisions.dup
78
76
  state_data.reject { |_, data| data['geo'] }.each do |code, data|
79
- location = "#{data['name']}, #{c.name}"
77
+ location = "#{c.alpha2}-#{code}"
80
78
 
81
- # Handle special geocoding cases where Google defaults to well known
82
- # cities, instead of the states.
83
- if c.alpha2 == 'US' && %w(NY WA OK).include?(code)
84
- location = "#{data['name']} State, United States"
85
- end
79
+ next unless (result = geocode(location, {region: c.alpha2}))
86
80
 
87
- next unless (result = geocode(location))
88
81
  geometry = result.geometry
89
82
  if geometry['location']
90
83
  state_data[code]['geo'] ||= {}
@@ -0,0 +1,48 @@
1
+ namespace :postal_codes do
2
+ desc 'Retrieve and update postal codes and their format'
3
+ task :update do
4
+ require 'json'
5
+ require 'open-uri'
6
+ require 'yaml'
7
+
8
+ country_files = Dir['lib/countries/data/countries/*.yaml'].sort
9
+
10
+ country_files.each do |country_file|
11
+ yaml = YAML.load_file(country_file)
12
+ country_code = File.basename(country_file, File.extname(country_file))
13
+ print "\rUpdating #{country_code}"
14
+
15
+ data = yaml[country_code].to_a
16
+ postal_code_index = data.find_index { |d| d[0] == 'postal_code' }
17
+ postal_code_format_index = data.find_index { |d| d[0] == 'postal_code_format' }
18
+
19
+ response = URI.open("https://chromium-i18n.appspot.com/ssl-address/data/#{country_code}").read
20
+ json = JSON.parse(response) rescue {}
21
+ puts ' - Returned empty data. Skipping ' and next if json.empty?
22
+
23
+ postal_code = ['postal_code', !!json['zip']]
24
+ postal_code_format = ['postal_code_format', json['zip']]
25
+
26
+ if postal_code_index
27
+ data[postal_code_index] = postal_code
28
+ else
29
+ postal_code_index = data.find_index { |d| d[0] == 'nationality' } + 1 || data.size
30
+ data.insert(postal_code_index, postal_code)
31
+ end
32
+
33
+ if json['zip']
34
+ if postal_code_format_index
35
+ data[postal_code_format_index] = postal_code_format
36
+ else
37
+ data.insert(postal_code_index + 1, postal_code_format)
38
+ end
39
+ elsif postal_code_format_index
40
+ data.delete_at(postal_code_format_index)
41
+ end
42
+
43
+ yaml[country_code] = data.to_h
44
+
45
+ File.open(country_file, 'w') { |file| file.write(yaml.to_yaml) }
46
+ end
47
+ end
48
+ end
@@ -6,7 +6,7 @@ module ISO3166
6
6
  # to `pt` to prevent from showing nil values
7
7
  class Translations < Hash
8
8
  def [](locale)
9
- super(locale) || super(locale.sub(/-.*/, ''))
9
+ super(locale) || super(locale.to_s.sub(/-.*/, ''))
10
10
  end
11
11
  end
12
12
  end
@@ -1,3 +1,3 @@
1
1
  module Countries
2
- VERSION = '3.0.1'.freeze
2
+ VERSION = '4.1.0'.freeze
3
3
  end
data/lib/countries.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'unicode_utils/downcase'
2
1
  require 'sixarm_ruby_unaccent'
3
2
 
4
3
  require 'countries/version'
data/spec/country_spec.rb CHANGED
@@ -85,8 +85,18 @@ describe ISO3166::Country do
85
85
  end
86
86
 
87
87
  it 'knows when a country does not require postal codes' do
88
- ireland = ISO3166::Country.search('IE')
89
- expect(ireland.postal_code).to eq(false)
88
+ antarctica = ISO3166::Country.search('AQ')
89
+ expect(antarctica.postal_code).to eq(false)
90
+ end
91
+
92
+ it 'knows about the country postal code format' do
93
+ expect(country.postal_code_format).to_not be_nil
94
+
95
+ regex = Regexp.new(country.postal_code_format)
96
+ expect(regex).to match("12345-6789")
97
+
98
+ antarctica = ISO3166::Country.search('AQ')
99
+ expect(antarctica.postal_code_format).to be_nil
90
100
  end
91
101
 
92
102
  it 'should return region' do
@@ -238,6 +248,10 @@ describe ISO3166::Country do
238
248
  expect(virginia.name).to eq('Virginia')
239
249
  end
240
250
 
251
+ it 'should have a code' do
252
+ expect(virginia.code).to eq('VA')
253
+ end
254
+
241
255
  it 'should behave like a hash' do
242
256
  expect(virginia['name']).to eq('Virginia')
243
257
  end
@@ -335,6 +349,26 @@ describe ISO3166::Country do
335
349
  expect(countries.first).to eq('Aruba')
336
350
  expect(countries.size).to eq(NUM_OF_COUNTRIES)
337
351
  end
352
+
353
+ context 'with custom countries' do
354
+ before do
355
+ ISO3166::Data.register(
356
+ alpha2: 'XX',
357
+ name: 'Custom Country',
358
+ translations: { 'en' => 'Custom Country' }
359
+ )
360
+ end
361
+
362
+ it 'should include custom registered countries' do
363
+ custom_country = ISO3166::Country.find_by_alpha2('XX')[1]
364
+ countries = ISO3166::Country.all_translated
365
+ expect(countries).to include(custom_country['name'])
366
+ end
367
+
368
+ after do
369
+ ISO3166::Data.unregister('XX')
370
+ end
371
+ end
338
372
  end
339
373
 
340
374
  describe 'all_names_with_codes' do
@@ -828,6 +862,23 @@ describe ISO3166::Country do
828
862
  end
829
863
  end
830
864
 
865
+ describe 'in_esm?' do
866
+ let(:netherlands) { ISO3166::Country.search('NL') }
867
+ let(:switzerland) { ISO3166::Country.search('CH') }
868
+
869
+ it 'should return false for countries without esm_member or eea_member flag' do
870
+ expect(country.in_esm?).to be_falsey
871
+ end
872
+
873
+ it 'should return true for countries with eea_member flag set to true' do
874
+ expect(netherlands.in_esm?).to be_truthy
875
+ end
876
+
877
+ it 'should return true for countries with esm_member flag set to true' do
878
+ expect(switzerland.in_esm?).to be_truthy
879
+ end
880
+ end
881
+
831
882
  describe 'gec' do
832
883
  it 'should return the country\'s GEC code' do
833
884
  expect(ISO3166::Country.new('NA').gec).to eql 'WA'
@@ -921,4 +972,24 @@ describe ISO3166::Country do
921
972
  expect(countries.all? { |country| country.un_locode.length == 2 }).to be
922
973
  end
923
974
  end
975
+
976
+ describe '.pluck' do
977
+ let(:args) { [] }
978
+
979
+ subject { ISO3166::Country.pluck(*args) }
980
+
981
+ it "returns empty arrays" do
982
+ expect(subject.first).to be_empty
983
+ expect(subject.last).to be_empty
984
+ end
985
+
986
+ context "when asking for alpha2, alpha3 and name" do
987
+ let(:args) { [:alpha2, :alpha3, :name] }
988
+
989
+ it "returns the correct values" do
990
+ expect(subject.first).to eq(["AD", "AND", "Andorra"])
991
+ expect(subject.last).to eq(["ZW", "ZWE", "Zimbabwe"])
992
+ end
993
+ end
994
+ end
924
995
  end
data/spec/data_spec.rb CHANGED
@@ -116,8 +116,8 @@ describe ISO3166::Data do
116
116
  expect(subject.name).to eq 'NEW Taiwan'
117
117
  expect(subject.translations).to eq('en' => 'NEW Taiwan',
118
118
  'de' => 'NEW Taiwan')
119
- expect(subject.subdivisions).to eq(CHA: ISO3166::Subdivision.new({name: 'New Changhua'}),
120
- CYI: ISO3166::Subdivision.new({name: 'New Municipality'}))
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'}))
121
121
  end
122
122
  end
123
123
 
@@ -143,8 +143,8 @@ describe ISO3166::Data do
143
143
  data = ISO3166::Data.new('LOL').call
144
144
  expect(data['name']).to eq 'Happy Country'
145
145
  expect(subject.name).to eq 'Happy Country'
146
- expect(subject.subdivisions).to eq(LOL1: ISO3166::Subdivision.new({name: 'Happy sub1'}),
147
- LOL2: ISO3166::Subdivision.new({name: 'Happy sub2'}))
146
+ expect(subject.subdivisions).to eq('LOL1' => ISO3166::Subdivision.new({name: 'Happy sub1', code: 'LOL1'}),
147
+ 'LOL2' => ISO3166::Subdivision.new({name: 'Happy sub2', code: 'LOL2'}))
148
148
  end
149
149
 
150
150
  it 'detect a stale cache' do
@@ -0,0 +1,46 @@
1
+ describe 'Accessing ISO3166::Country instances data in multiple threads' do
2
+ before do
3
+ if Thread.respond_to?(:report_on_exception)
4
+ @report_on_exception_value = Thread.report_on_exception
5
+ Thread.report_on_exception = false
6
+ end
7
+
8
+ ISO3166::Data.reset
9
+ end
10
+
11
+ def create_countries_threaded
12
+ nthreads = 100
13
+ threads = []
14
+
15
+ alpha2_codes = ['us', 'es', 'nl', 'ca', 'de', 'fr', 'mx', 'ru', 'ch', 'jp']
16
+
17
+ nthreads.times do
18
+ threads << Thread.new do
19
+ alpha2_codes.each do |a2|
20
+ country = ISO3166::Country[a2]
21
+ # This will fail if data['translations'] has been
22
+ # left nil due to a race condition
23
+ country.translation
24
+ end
25
+ end
26
+ end
27
+ threads.map(&:join)
28
+ end
29
+
30
+ it "doesn't raise any exceptions when using a mutex" do
31
+ expect { create_countries_threaded }.to_not raise_error
32
+ end
33
+
34
+ it "raises NoMethodError when not using a mutex" do
35
+ allow(ISO3166::Data).to receive(:use_mutex?).and_return(false)
36
+
37
+ expect { create_countries_threaded }.to raise_error(NoMethodError)
38
+ end
39
+
40
+ after do
41
+ if Thread.respond_to?(:report_on_exception)
42
+ Thread.report_on_exception = @report_on_exception_value
43
+ end
44
+ end
45
+ end
46
+
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: countries
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Robinson
8
8
  - Joe Corcoran
9
9
  - Russell Osborne
10
- autorequire:
10
+ - Pedro Moreira
11
+ autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2020-02-11 00:00:00.000000000 Z
14
+ date: 2021-11-30 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: i18n_data
@@ -18,28 +19,14 @@ dependencies:
18
19
  requirements:
19
20
  - - "~>"
20
21
  - !ruby/object:Gem::Version
21
- version: 0.10.0
22
+ version: 0.13.1
22
23
  type: :runtime
23
24
  prerelease: false
24
25
  version_requirements: !ruby/object:Gem::Requirement
25
26
  requirements:
26
27
  - - "~>"
27
28
  - !ruby/object:Gem::Version
28
- version: 0.10.0
29
- - !ruby/object:Gem::Dependency
30
- name: unicode_utils
31
- requirement: !ruby/object:Gem::Requirement
32
- requirements:
33
- - - "~>"
34
- - !ruby/object:Gem::Version
35
- version: '1.4'
36
- type: :runtime
37
- prerelease: false
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - "~>"
41
- - !ruby/object:Gem::Version
42
- version: '1.4'
29
+ version: 0.13.1
43
30
  - !ruby/object:Gem::Dependency
44
31
  name: sixarm_ruby_unaccent
45
32
  requirement: !ruby/object:Gem::Requirement
@@ -101,15 +88,16 @@ description: All sorts of useful information about every country packaged as pre
101
88
  email:
102
89
  - hexorx@gmail.com
103
90
  - russell@burningpony.com
91
+ - pedro@codecreations.tech
104
92
  executables: []
105
93
  extensions: []
106
94
  extra_rdoc_files: []
107
95
  files:
96
+ - ".github/workflows/tests.yml"
108
97
  - ".gitignore"
109
98
  - ".rspec"
110
99
  - ".rubocop.yml"
111
100
  - ".rubocop_todo.yml"
112
- - ".travis.yml"
113
101
  - CHANGELOG.md
114
102
  - Gemfile
115
103
  - LICENSE
@@ -518,6 +506,7 @@ files:
518
506
  - lib/countries/data/subdivisions/AS.yaml
519
507
  - lib/countries/data/subdivisions/AT.yaml
520
508
  - lib/countries/data/subdivisions/AU.yaml
509
+ - lib/countries/data/subdivisions/AW.yaml
521
510
  - lib/countries/data/subdivisions/AX.yaml
522
511
  - lib/countries/data/subdivisions/AZ.yaml
523
512
  - lib/countries/data/subdivisions/BA.yaml
@@ -529,6 +518,7 @@ files:
529
518
  - lib/countries/data/subdivisions/BH.yaml
530
519
  - lib/countries/data/subdivisions/BI.yaml
531
520
  - lib/countries/data/subdivisions/BJ.yaml
521
+ - lib/countries/data/subdivisions/BL.yaml
532
522
  - lib/countries/data/subdivisions/BM.yaml
533
523
  - lib/countries/data/subdivisions/BN.yaml
534
524
  - lib/countries/data/subdivisions/BO.yaml
@@ -550,9 +540,11 @@ files:
550
540
  - lib/countries/data/subdivisions/CM.yaml
551
541
  - lib/countries/data/subdivisions/CN.yaml
552
542
  - lib/countries/data/subdivisions/CO.yaml
543
+ - lib/countries/data/subdivisions/CP.yaml
553
544
  - lib/countries/data/subdivisions/CR.yaml
554
545
  - lib/countries/data/subdivisions/CU.yaml
555
546
  - lib/countries/data/subdivisions/CV.yaml
547
+ - lib/countries/data/subdivisions/CW.yaml
556
548
  - lib/countries/data/subdivisions/CY.yaml
557
549
  - lib/countries/data/subdivisions/CZ.yaml
558
550
  - lib/countries/data/subdivisions/DE.yaml
@@ -577,11 +569,13 @@ files:
577
569
  - lib/countries/data/subdivisions/GB.yaml
578
570
  - lib/countries/data/subdivisions/GD.yaml
579
571
  - lib/countries/data/subdivisions/GE.yaml
572
+ - lib/countries/data/subdivisions/GF.yaml
580
573
  - lib/countries/data/subdivisions/GG.yaml
581
574
  - lib/countries/data/subdivisions/GH.yaml
582
575
  - lib/countries/data/subdivisions/GL.yaml
583
576
  - lib/countries/data/subdivisions/GM.yaml
584
577
  - lib/countries/data/subdivisions/GN.yaml
578
+ - lib/countries/data/subdivisions/GP.yaml
585
579
  - lib/countries/data/subdivisions/GQ.yaml
586
580
  - lib/countries/data/subdivisions/GR.yaml
587
581
  - lib/countries/data/subdivisions/GT.yaml
@@ -593,6 +587,7 @@ files:
593
587
  - lib/countries/data/subdivisions/HR.yaml
594
588
  - lib/countries/data/subdivisions/HT.yaml
595
589
  - lib/countries/data/subdivisions/HU.yaml
590
+ - lib/countries/data/subdivisions/IC.yaml
596
591
  - lib/countries/data/subdivisions/ID.yaml
597
592
  - lib/countries/data/subdivisions/IE.yaml
598
593
  - lib/countries/data/subdivisions/IL.yaml
@@ -632,13 +627,16 @@ files:
632
627
  - lib/countries/data/subdivisions/MC.yaml
633
628
  - lib/countries/data/subdivisions/MD.yaml
634
629
  - lib/countries/data/subdivisions/ME.yaml
630
+ - lib/countries/data/subdivisions/MF.yaml
635
631
  - lib/countries/data/subdivisions/MG.yaml
636
632
  - lib/countries/data/subdivisions/MH.yaml
637
633
  - lib/countries/data/subdivisions/MK.yaml
638
634
  - lib/countries/data/subdivisions/ML.yaml
639
635
  - lib/countries/data/subdivisions/MM.yaml
640
636
  - lib/countries/data/subdivisions/MN.yaml
637
+ - lib/countries/data/subdivisions/MO.yaml
641
638
  - lib/countries/data/subdivisions/MP.yaml
639
+ - lib/countries/data/subdivisions/MQ.yaml
642
640
  - lib/countries/data/subdivisions/MR.yaml
643
641
  - lib/countries/data/subdivisions/MS.yaml
644
642
  - lib/countries/data/subdivisions/MT.yaml
@@ -673,6 +671,7 @@ files:
673
671
  - lib/countries/data/subdivisions/PW.yaml
674
672
  - lib/countries/data/subdivisions/PY.yaml
675
673
  - lib/countries/data/subdivisions/QA.yaml
674
+ - lib/countries/data/subdivisions/RE.yaml
676
675
  - lib/countries/data/subdivisions/RO.yaml
677
676
  - lib/countries/data/subdivisions/RS.yaml
678
677
  - lib/countries/data/subdivisions/RU.yaml
@@ -695,8 +694,10 @@ files:
695
694
  - lib/countries/data/subdivisions/SS.yaml
696
695
  - lib/countries/data/subdivisions/ST.yaml
697
696
  - lib/countries/data/subdivisions/SV.yaml
697
+ - lib/countries/data/subdivisions/SX.yaml
698
698
  - lib/countries/data/subdivisions/SY.yaml
699
699
  - lib/countries/data/subdivisions/SZ.yaml
700
+ - lib/countries/data/subdivisions/TA.yaml
700
701
  - lib/countries/data/subdivisions/TD.yaml
701
702
  - lib/countries/data/subdivisions/TF.yaml
702
703
  - lib/countries/data/subdivisions/TG.yaml
@@ -745,6 +746,7 @@ files:
745
746
  - lib/countries/structure.rb
746
747
  - lib/countries/subdivision.rb
747
748
  - lib/countries/tasks/geocoding.rake
749
+ - lib/countries/tasks/postal_codes.rake
748
750
  - lib/countries/timezones.rb
749
751
  - lib/countries/translations.rb
750
752
  - lib/countries/version.rb
@@ -756,12 +758,17 @@ files:
756
758
  - spec/perf_spec.rb
757
759
  - spec/spec_helper.rb
758
760
  - spec/subdivision_spec.rb
761
+ - spec/thread_safety_spec.rb
759
762
  - spec/timezone_spec.rb
760
- homepage: http://github.com/hexorx/countries
763
+ homepage: http://github.com/countries/countries
761
764
  licenses:
762
765
  - MIT
763
- metadata: {}
764
- post_install_message:
766
+ metadata:
767
+ bug_tracker_uri: http://github.com/countries/countries/issues
768
+ changelog_uri: https://github.com/countries/countries/blob/master/CHANGELOG.md
769
+ source_code_uri: https://github.com/countries/countries
770
+ wiki_uri: https://github.com/countries/countries/wiki
771
+ post_install_message:
765
772
  rdoc_options: []
766
773
  require_paths:
767
774
  - lib
@@ -769,15 +776,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
769
776
  requirements:
770
777
  - - ">="
771
778
  - !ruby/object:Gem::Version
772
- version: '0'
779
+ version: '2.5'
773
780
  required_rubygems_version: !ruby/object:Gem::Requirement
774
781
  requirements:
775
782
  - - ">="
776
783
  - !ruby/object:Gem::Version
777
784
  version: '0'
778
785
  requirements: []
779
- rubygems_version: 3.0.3
780
- signing_key:
786
+ rubygems_version: 3.2.32
787
+ signing_key:
781
788
  specification_version: 4
782
789
  summary: Gives you a country object full of all sorts of useful information.
783
790
  test_files:
@@ -789,4 +796,5 @@ test_files:
789
796
  - spec/perf_spec.rb
790
797
  - spec/spec_helper.rb
791
798
  - spec/subdivision_spec.rb
799
+ - spec/thread_safety_spec.rb
792
800
  - spec/timezone_spec.rb