countries 3.0.1 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +37 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +104 -1
- data/Gemfile +5 -0
- data/README.markdown +51 -35
- data/Rakefile +5 -3
- data/countries.gemspec +10 -5
- data/lib/countries/cache/countries.json +1 -1
- data/lib/countries/cache/locales/ab.json +1 -1
- data/lib/countries/cache/locales/af.json +1 -1
- data/lib/countries/cache/locales/ak.json +1 -1
- data/lib/countries/cache/locales/am.json +1 -1
- data/lib/countries/cache/locales/an.json +1 -1
- data/lib/countries/cache/locales/ar.json +1 -1
- data/lib/countries/cache/locales/as.json +1 -1
- data/lib/countries/cache/locales/ay.json +1 -1
- data/lib/countries/cache/locales/az.json +1 -1
- data/lib/countries/cache/locales/ba.json +1 -1
- data/lib/countries/cache/locales/be.json +1 -1
- data/lib/countries/cache/locales/bg.json +1 -1
- data/lib/countries/cache/locales/bi.json +1 -1
- data/lib/countries/cache/locales/bn-in.json +1 -1
- data/lib/countries/cache/locales/bn.json +1 -1
- data/lib/countries/cache/locales/br.json +1 -1
- data/lib/countries/cache/locales/bs.json +1 -1
- data/lib/countries/cache/locales/ca.json +1 -1
- data/lib/countries/cache/locales/ce.json +1 -1
- data/lib/countries/cache/locales/ch.json +1 -1
- data/lib/countries/cache/locales/cs.json +1 -1
- data/lib/countries/cache/locales/cv.json +1 -1
- data/lib/countries/cache/locales/cy.json +1 -1
- data/lib/countries/cache/locales/da.json +1 -1
- data/lib/countries/cache/locales/de.json +1 -1
- data/lib/countries/cache/locales/dv.json +1 -1
- data/lib/countries/cache/locales/dz.json +1 -1
- data/lib/countries/cache/locales/ee.json +1 -1
- data/lib/countries/cache/locales/el.json +1 -1
- data/lib/countries/cache/locales/en.json +1 -1
- data/lib/countries/cache/locales/eo.json +1 -1
- data/lib/countries/cache/locales/es.json +1 -1
- data/lib/countries/cache/locales/et.json +1 -1
- data/lib/countries/cache/locales/eu.json +1 -1
- data/lib/countries/cache/locales/fa.json +1 -1
- data/lib/countries/cache/locales/ff.json +1 -1
- data/lib/countries/cache/locales/fi.json +1 -1
- data/lib/countries/cache/locales/fo.json +1 -1
- data/lib/countries/cache/locales/fr.json +1 -1
- data/lib/countries/cache/locales/fy.json +1 -1
- data/lib/countries/cache/locales/ga.json +1 -1
- data/lib/countries/cache/locales/gl.json +1 -1
- data/lib/countries/cache/locales/gn.json +1 -1
- data/lib/countries/cache/locales/gu.json +1 -1
- data/lib/countries/cache/locales/gv.json +1 -1
- data/lib/countries/cache/locales/ha.json +1 -1
- data/lib/countries/cache/locales/he.json +1 -1
- data/lib/countries/cache/locales/hi.json +1 -1
- data/lib/countries/cache/locales/hr.json +1 -1
- data/lib/countries/cache/locales/ht.json +1 -1
- data/lib/countries/cache/locales/hu.json +1 -1
- data/lib/countries/cache/locales/hy.json +1 -1
- data/lib/countries/cache/locales/ia.json +1 -1
- data/lib/countries/cache/locales/id.json +1 -1
- data/lib/countries/cache/locales/io.json +1 -1
- data/lib/countries/cache/locales/is.json +1 -1
- data/lib/countries/cache/locales/it.json +1 -1
- data/lib/countries/cache/locales/iu.json +1 -1
- data/lib/countries/cache/locales/ja.json +1 -1
- data/lib/countries/cache/locales/ka.json +1 -1
- data/lib/countries/cache/locales/ki.json +1 -1
- data/lib/countries/cache/locales/kk.json +1 -1
- data/lib/countries/cache/locales/kl.json +1 -1
- data/lib/countries/cache/locales/km.json +1 -1
- data/lib/countries/cache/locales/kn.json +1 -1
- data/lib/countries/cache/locales/ko.json +1 -1
- data/lib/countries/cache/locales/ku.json +1 -1
- data/lib/countries/cache/locales/kv.json +1 -1
- data/lib/countries/cache/locales/kw.json +1 -1
- data/lib/countries/cache/locales/ky.json +1 -1
- data/lib/countries/cache/locales/lo.json +1 -1
- data/lib/countries/cache/locales/lt.json +1 -1
- data/lib/countries/cache/locales/lv.json +1 -1
- data/lib/countries/cache/locales/mi.json +1 -1
- data/lib/countries/cache/locales/mk.json +1 -1
- data/lib/countries/cache/locales/ml.json +1 -1
- data/lib/countries/cache/locales/mn.json +1 -1
- data/lib/countries/cache/locales/mr.json +1 -1
- data/lib/countries/cache/locales/ms.json +1 -1
- data/lib/countries/cache/locales/mt.json +1 -1
- data/lib/countries/cache/locales/my.json +1 -1
- data/lib/countries/cache/locales/na.json +1 -1
- data/lib/countries/cache/locales/nb.json +1 -1
- data/lib/countries/cache/locales/ne.json +1 -1
- data/lib/countries/cache/locales/nl.json +1 -1
- data/lib/countries/cache/locales/nn.json +1 -1
- data/lib/countries/cache/locales/nv.json +1 -1
- data/lib/countries/cache/locales/oc.json +1 -1
- data/lib/countries/cache/locales/or.json +1 -1
- data/lib/countries/cache/locales/pa.json +1 -1
- data/lib/countries/cache/locales/pi.json +1 -1
- data/lib/countries/cache/locales/pl.json +1 -1
- data/lib/countries/cache/locales/ps.json +1 -1
- data/lib/countries/cache/locales/pt-br.json +1 -1
- data/lib/countries/cache/locales/pt.json +1 -1
- data/lib/countries/cache/locales/ro.json +1 -1
- data/lib/countries/cache/locales/ru.json +1 -1
- data/lib/countries/cache/locales/rw.json +1 -1
- data/lib/countries/cache/locales/sc.json +1 -1
- data/lib/countries/cache/locales/sd.json +1 -1
- data/lib/countries/cache/locales/si.json +1 -1
- data/lib/countries/cache/locales/sk.json +1 -1
- data/lib/countries/cache/locales/sl.json +1 -1
- data/lib/countries/cache/locales/so.json +1 -1
- data/lib/countries/cache/locales/sq.json +1 -1
- data/lib/countries/cache/locales/sr.json +1 -1
- data/lib/countries/cache/locales/sv.json +1 -1
- data/lib/countries/cache/locales/sw.json +1 -1
- data/lib/countries/cache/locales/ta.json +1 -1
- data/lib/countries/cache/locales/te.json +1 -1
- data/lib/countries/cache/locales/tg.json +1 -1
- data/lib/countries/cache/locales/th.json +1 -1
- data/lib/countries/cache/locales/ti.json +1 -1
- data/lib/countries/cache/locales/tk.json +1 -1
- data/lib/countries/cache/locales/tl.json +1 -1
- data/lib/countries/cache/locales/tr.json +1 -1
- data/lib/countries/cache/locales/tt.json +1 -1
- data/lib/countries/cache/locales/ug.json +1 -1
- data/lib/countries/cache/locales/uk.json +1 -1
- data/lib/countries/cache/locales/ur.json +1 -1
- data/lib/countries/cache/locales/uz.json +1 -1
- data/lib/countries/cache/locales/ve.json +1 -1
- data/lib/countries/cache/locales/vi.json +1 -1
- data/lib/countries/cache/locales/wa.json +1 -1
- data/lib/countries/cache/locales/wo.json +1 -1
- data/lib/countries/cache/locales/xh.json +1 -1
- data/lib/countries/cache/locales/yo.json +1 -1
- data/lib/countries/cache/locales/zh-cn.json +1 -1
- data/lib/countries/cache/locales/zh-hk.json +1 -1
- data/lib/countries/cache/locales/zh-tw.json +1 -1
- data/lib/countries/cache/locales/zh.json +1 -1
- data/lib/countries/cache/locales/zu.json +1 -1
- data/lib/countries/country/class_methods.rb +18 -4
- data/lib/countries/country.rb +5 -0
- data/lib/countries/data/countries/AD.yaml +1 -0
- data/lib/countries/data/countries/AF.yaml +1 -0
- data/lib/countries/data/countries/AG.yaml +1 -1
- data/lib/countries/data/countries/AI.yaml +1 -0
- data/lib/countries/data/countries/AL.yaml +4 -3
- data/lib/countries/data/countries/AM.yaml +3 -2
- data/lib/countries/data/countries/AO.yaml +10 -10
- data/lib/countries/data/countries/AQ.yaml +3 -3
- data/lib/countries/data/countries/AR.yaml +1 -0
- data/lib/countries/data/countries/AS.yaml +3 -2
- data/lib/countries/data/countries/AT.yaml +4 -3
- data/lib/countries/data/countries/AU.yaml +1 -0
- data/lib/countries/data/countries/AX.yaml +1 -0
- data/lib/countries/data/countries/AZ.yaml +1 -0
- data/lib/countries/data/countries/BA.yaml +5 -4
- data/lib/countries/data/countries/BB.yaml +1 -0
- data/lib/countries/data/countries/BD.yaml +3 -2
- data/lib/countries/data/countries/BE.yaml +2 -1
- data/lib/countries/data/countries/BF.yaml +8 -8
- data/lib/countries/data/countries/BG.yaml +5 -4
- data/lib/countries/data/countries/BH.yaml +6 -5
- data/lib/countries/data/countries/BI.yaml +6 -6
- data/lib/countries/data/countries/BJ.yaml +2 -2
- data/lib/countries/data/countries/BL.yaml +1 -0
- data/lib/countries/data/countries/BM.yaml +1 -0
- data/lib/countries/data/countries/BN.yaml +2 -1
- data/lib/countries/data/countries/BO.yaml +1 -1
- data/lib/countries/data/countries/BQ.yaml +1 -1
- data/lib/countries/data/countries/BR.yaml +7 -6
- data/lib/countries/data/countries/BT.yaml +7 -6
- data/lib/countries/data/countries/BV.yaml +11 -11
- data/lib/countries/data/countries/BW.yaml +4 -4
- data/lib/countries/data/countries/BY.yaml +1 -0
- data/lib/countries/data/countries/BZ.yaml +1 -1
- data/lib/countries/data/countries/CA.yaml +1 -0
- data/lib/countries/data/countries/CC.yaml +3 -2
- data/lib/countries/data/countries/CF.yaml +2 -2
- data/lib/countries/data/countries/CG.yaml +2 -2
- data/lib/countries/data/countries/CH.yaml +4 -3
- data/lib/countries/data/countries/CI.yaml +2 -2
- data/lib/countries/data/countries/CL.yaml +8 -2
- data/lib/countries/data/countries/CN.yaml +5 -4
- data/lib/countries/data/countries/CO.yaml +5 -4
- data/lib/countries/data/countries/CR.yaml +3 -2
- data/lib/countries/data/countries/CU.yaml +1 -0
- data/lib/countries/data/countries/CV.yaml +3 -2
- data/lib/countries/data/countries/CW.yaml +1 -1
- data/lib/countries/data/countries/CX.yaml +1 -0
- data/lib/countries/data/countries/CY.yaml +3 -2
- data/lib/countries/data/countries/CZ.yaml +4 -3
- data/lib/countries/data/countries/DE.yaml +3 -2
- data/lib/countries/data/countries/DJ.yaml +6 -6
- data/lib/countries/data/countries/DK.yaml +3 -2
- data/lib/countries/data/countries/DO.yaml +1 -0
- data/lib/countries/data/countries/DZ.yaml +7 -6
- data/lib/countries/data/countries/EC.yaml +5 -4
- data/lib/countries/data/countries/EE.yaml +4 -3
- data/lib/countries/data/countries/EG.yaml +1 -0
- data/lib/countries/data/countries/EH.yaml +1 -0
- data/lib/countries/data/countries/ES.yaml +2 -1
- data/lib/countries/data/countries/ET.yaml +1 -0
- data/lib/countries/data/countries/FI.yaml +6 -5
- data/lib/countries/data/countries/FK.yaml +3 -2
- data/lib/countries/data/countries/FM.yaml +3 -2
- data/lib/countries/data/countries/FO.yaml +6 -5
- data/lib/countries/data/countries/FR.yaml +4 -3
- data/lib/countries/data/countries/GA.yaml +1 -1
- data/lib/countries/data/countries/GB.yaml +4 -0
- data/lib/countries/data/countries/GE.yaml +5 -4
- data/lib/countries/data/countries/GF.yaml +1 -0
- data/lib/countries/data/countries/GG.yaml +11 -10
- data/lib/countries/data/countries/GH.yaml +4 -4
- data/lib/countries/data/countries/GI.yaml +3 -2
- data/lib/countries/data/countries/GL.yaml +8 -7
- data/lib/countries/data/countries/GM.yaml +4 -4
- data/lib/countries/data/countries/GN.yaml +4 -3
- data/lib/countries/data/countries/GP.yaml +1 -0
- data/lib/countries/data/countries/GR.yaml +3 -2
- data/lib/countries/data/countries/GS.yaml +3 -2
- data/lib/countries/data/countries/GT.yaml +3 -2
- data/lib/countries/data/countries/GU.yaml +1 -0
- data/lib/countries/data/countries/GW.yaml +1 -0
- data/lib/countries/data/countries/HK.yaml +4 -4
- data/lib/countries/data/countries/HM.yaml +2 -1
- data/lib/countries/data/countries/HN.yaml +3 -2
- data/lib/countries/data/countries/HR.yaml +4 -3
- data/lib/countries/data/countries/HT.yaml +1 -0
- data/lib/countries/data/countries/HU.yaml +8 -7
- data/lib/countries/data/countries/ID.yaml +1 -0
- data/lib/countries/data/countries/IE.yaml +12 -11
- data/lib/countries/data/countries/IL.yaml +1 -0
- data/lib/countries/data/countries/IM.yaml +9 -8
- data/lib/countries/data/countries/IN.yaml +3 -2
- data/lib/countries/data/countries/IO.yaml +4 -3
- data/lib/countries/data/countries/IQ.yaml +3 -2
- data/lib/countries/data/countries/IR.yaml +1 -0
- data/lib/countries/data/countries/IS.yaml +6 -5
- data/lib/countries/data/countries/IT.yaml +2 -1
- data/lib/countries/data/countries/JE.yaml +1 -0
- data/lib/countries/data/countries/JO.yaml +3 -2
- data/lib/countries/data/countries/JP.yaml +1 -0
- data/lib/countries/data/countries/KE.yaml +4 -3
- data/lib/countries/data/countries/KG.yaml +3 -2
- data/lib/countries/data/countries/KH.yaml +1 -0
- data/lib/countries/data/countries/KI.yaml +6 -6
- data/lib/countries/data/countries/KP.yaml +3 -2
- data/lib/countries/data/countries/KR.yaml +1 -0
- data/lib/countries/data/countries/KW.yaml +1 -0
- data/lib/countries/data/countries/KY.yaml +1 -0
- data/lib/countries/data/countries/KZ.yaml +3 -2
- data/lib/countries/data/countries/LA.yaml +7 -6
- data/lib/countries/data/countries/LB.yaml +1 -0
- data/lib/countries/data/countries/LI.yaml +1 -0
- data/lib/countries/data/countries/LK.yaml +1 -0
- data/lib/countries/data/countries/LR.yaml +1 -0
- data/lib/countries/data/countries/LS.yaml +1 -0
- data/lib/countries/data/countries/LT.yaml +7 -6
- data/lib/countries/data/countries/LU.yaml +1 -0
- data/lib/countries/data/countries/LV.yaml +11 -4
- data/lib/countries/data/countries/LY.yaml +1 -1
- data/lib/countries/data/countries/MA.yaml +5 -4
- data/lib/countries/data/countries/MC.yaml +1 -0
- data/lib/countries/data/countries/MD.yaml +9 -8
- data/lib/countries/data/countries/ME.yaml +3 -2
- data/lib/countries/data/countries/MF.yaml +1 -0
- data/lib/countries/data/countries/MG.yaml +1 -0
- data/lib/countries/data/countries/MH.yaml +3 -2
- data/lib/countries/data/countries/MK.yaml +3 -2
- data/lib/countries/data/countries/ML.yaml +4 -4
- data/lib/countries/data/countries/MM.yaml +1 -0
- data/lib/countries/data/countries/MN.yaml +9 -8
- data/lib/countries/data/countries/MP.yaml +1 -0
- data/lib/countries/data/countries/MQ.yaml +1 -0
- data/lib/countries/data/countries/MR.yaml +2 -2
- data/lib/countries/data/countries/MT.yaml +3 -2
- data/lib/countries/data/countries/MU.yaml +2 -1
- data/lib/countries/data/countries/MV.yaml +3 -2
- data/lib/countries/data/countries/MW.yaml +2 -2
- data/lib/countries/data/countries/MX.yaml +5 -4
- data/lib/countries/data/countries/MY.yaml +3 -2
- data/lib/countries/data/countries/MZ.yaml +1 -0
- data/lib/countries/data/countries/NA.yaml +5 -4
- data/lib/countries/data/countries/NC.yaml +1 -0
- data/lib/countries/data/countries/NE.yaml +5 -4
- data/lib/countries/data/countries/NF.yaml +1 -0
- data/lib/countries/data/countries/NG.yaml +2 -1
- data/lib/countries/data/countries/NI.yaml +3 -2
- data/lib/countries/data/countries/NL.yaml +4 -3
- data/lib/countries/data/countries/NO.yaml +3 -2
- data/lib/countries/data/countries/NP.yaml +7 -6
- data/lib/countries/data/countries/NZ.yaml +3 -2
- data/lib/countries/data/countries/OM.yaml +3 -2
- data/lib/countries/data/countries/PA.yaml +2 -2
- data/lib/countries/data/countries/PE.yaml +5 -4
- data/lib/countries/data/countries/PF.yaml +5 -4
- data/lib/countries/data/countries/PG.yaml +1 -0
- data/lib/countries/data/countries/PH.yaml +5 -4
- data/lib/countries/data/countries/PK.yaml +5 -4
- data/lib/countries/data/countries/PL.yaml +5 -4
- data/lib/countries/data/countries/PM.yaml +1 -0
- data/lib/countries/data/countries/PN.yaml +1 -0
- data/lib/countries/data/countries/PR.yaml +9 -8
- data/lib/countries/data/countries/PS.yaml +1 -1
- data/lib/countries/data/countries/PT.yaml +6 -5
- data/lib/countries/data/countries/PW.yaml +1 -0
- data/lib/countries/data/countries/PY.yaml +3 -2
- data/lib/countries/data/countries/QA.yaml +2 -2
- data/lib/countries/data/countries/RE.yaml +1 -0
- data/lib/countries/data/countries/RO.yaml +7 -6
- data/lib/countries/data/countries/RS.yaml +1 -0
- data/lib/countries/data/countries/RU.yaml +3 -2
- data/lib/countries/data/countries/RW.yaml +2 -2
- data/lib/countries/data/countries/SA.yaml +4 -3
- data/lib/countries/data/countries/SB.yaml +1 -1
- data/lib/countries/data/countries/SC.yaml +2 -2
- data/lib/countries/data/countries/SD.yaml +3 -2
- data/lib/countries/data/countries/SE.yaml +5 -4
- data/lib/countries/data/countries/SG.yaml +1 -0
- data/lib/countries/data/countries/SH.yaml +5 -4
- data/lib/countries/data/countries/SI.yaml +5 -4
- data/lib/countries/data/countries/SJ.yaml +6 -5
- data/lib/countries/data/countries/SK.yaml +7 -6
- data/lib/countries/data/countries/SL.yaml +2 -2
- data/lib/countries/data/countries/SM.yaml +1 -0
- data/lib/countries/data/countries/SN.yaml +5 -4
- data/lib/countries/data/countries/SO.yaml +2 -1
- data/lib/countries/data/countries/SS.yaml +2 -2
- data/lib/countries/data/countries/SV.yaml +1 -0
- data/lib/countries/data/countries/SX.yaml +1 -1
- data/lib/countries/data/countries/SZ.yaml +1 -0
- data/lib/countries/data/countries/TC.yaml +1 -0
- data/lib/countries/data/countries/TD.yaml +1 -1
- data/lib/countries/data/countries/TF.yaml +5 -5
- data/lib/countries/data/countries/TG.yaml +7 -7
- data/lib/countries/data/countries/TH.yaml +3 -1
- data/lib/countries/data/countries/TJ.yaml +1 -0
- data/lib/countries/data/countries/TM.yaml +1 -0
- data/lib/countries/data/countries/TN.yaml +1 -0
- data/lib/countries/data/countries/TR.yaml +1 -0
- data/lib/countries/data/countries/TV.yaml +3 -3
- data/lib/countries/data/countries/TW.yaml +1 -0
- data/lib/countries/data/countries/TZ.yaml +4 -3
- data/lib/countries/data/countries/UA.yaml +7 -6
- data/lib/countries/data/countries/UG.yaml +4 -4
- data/lib/countries/data/countries/UM.yaml +1 -0
- data/lib/countries/data/countries/US.yaml +1 -0
- data/lib/countries/data/countries/UY.yaml +3 -2
- data/lib/countries/data/countries/UZ.yaml +1 -0
- data/lib/countries/data/countries/VA.yaml +1 -0
- data/lib/countries/data/countries/VC.yaml +3 -2
- data/lib/countries/data/countries/VE.yaml +3 -2
- data/lib/countries/data/countries/VG.yaml +2 -1
- data/lib/countries/data/countries/VI.yaml +1 -0
- data/lib/countries/data/countries/VN.yaml +11 -4
- data/lib/countries/data/countries/WF.yaml +1 -0
- data/lib/countries/data/countries/WS.yaml +3 -3
- data/lib/countries/data/countries/YT.yaml +1 -0
- data/lib/countries/data/countries/ZA.yaml +5 -4
- data/lib/countries/data/countries/ZM.yaml +5 -4
- data/lib/countries/data/countries/ZW.yaml +4 -4
- data/lib/countries/data/subdivisions/AD.yaml +35 -28
- data/lib/countries/data/subdivisions/AE.yaml +154 -63
- data/lib/countries/data/subdivisions/AF.yaml +605 -300
- data/lib/countries/data/subdivisions/AG.yaml +149 -67
- data/lib/countries/data/subdivisions/AI.yaml +139 -125
- data/lib/countries/data/subdivisions/AL.yaml +472 -144
- data/lib/countries/data/subdivisions/AM.yaml +236 -88
- data/lib/countries/data/subdivisions/AO.yaml +344 -144
- data/lib/countries/data/subdivisions/AR.yaml +450 -187
- data/lib/countries/data/subdivisions/AS.yaml +34 -15
- data/lib/countries/data/subdivisions/AT.yaml +202 -72
- data/lib/countries/data/subdivisions/AU.yaml +212 -64
- data/lib/countries/data/subdivisions/AW.yaml +9 -0
- data/lib/countries/data/subdivisions/AX.yaml +20 -9
- data/lib/countries/data/subdivisions/AZ.yaml +1550 -592
- data/lib/countries/data/subdivisions/BA.yaml +189 -16
- data/lib/countries/data/subdivisions/BB.yaml +190 -88
- data/lib/countries/data/subdivisions/BD.yaml +1192 -519
- data/lib/countries/data/subdivisions/BE.yaml +278 -88
- data/lib/countries/data/subdivisions/BF.yaml +993 -366
- data/lib/countries/data/subdivisions/BG.yaml +600 -219
- data/lib/countries/data/subdivisions/BH.yaml +72 -35
- data/lib/countries/data/subdivisions/BI.yaml +298 -123
- data/lib/countries/data/subdivisions/BJ.yaml +226 -96
- data/lib/countries/data/subdivisions/BL.yaml +11 -0
- data/lib/countries/data/subdivisions/BM.yaml +110 -99
- data/lib/countries/data/subdivisions/BN.yaml +63 -32
- data/lib/countries/data/subdivisions/BO.yaml +157 -72
- data/lib/countries/data/subdivisions/BQ.yaml +63 -24
- data/lib/countries/data/subdivisions/BR.yaml +689 -216
- data/lib/countries/data/subdivisions/BS.yaml +625 -108
- data/lib/countries/data/subdivisions/BT.yaml +346 -160
- data/lib/countries/data/subdivisions/BW.yaml +294 -72
- data/lib/countries/data/subdivisions/BY.yaml +140 -51
- data/lib/countries/data/subdivisions/BZ.yaml +97 -48
- data/lib/countries/data/subdivisions/CA.yaml +358 -105
- data/lib/countries/data/subdivisions/CD.yaml +451 -68
- data/lib/countries/data/subdivisions/CF.yaml +291 -136
- data/lib/countries/data/subdivisions/CG.yaml +217 -88
- data/lib/countries/data/subdivisions/CH.yaml +593 -208
- data/lib/countries/data/subdivisions/CI.yaml +431 -66
- data/lib/countries/data/subdivisions/CK.yaml +110 -99
- data/lib/countries/data/subdivisions/CL.yaml +262 -132
- data/lib/countries/data/subdivisions/CM.yaml +190 -80
- data/lib/countries/data/subdivisions/CN.yaml +725 -46
- data/lib/countries/data/subdivisions/CO.yaml +643 -264
- data/lib/countries/data/subdivisions/CP.yaml +4 -0
- data/lib/countries/data/subdivisions/CR.yaml +119 -56
- data/lib/countries/data/subdivisions/CU.yaml +268 -128
- data/lib/countries/data/subdivisions/CV.yaml +414 -126
- data/lib/countries/data/subdivisions/CW.yaml +9 -0
- data/lib/countries/data/subdivisions/CY.yaml +102 -48
- data/lib/countries/data/subdivisions/CZ.yaml +2430 -53
- data/lib/countries/data/subdivisions/DE.yaml +468 -128
- data/lib/countries/data/subdivisions/DJ.yaml +110 -48
- data/lib/countries/data/subdivisions/DK.yaml +186 -96
- data/lib/countries/data/subdivisions/DM.yaml +159 -80
- data/lib/countries/data/subdivisions/DO.yaml +660 -248
- data/lib/countries/data/subdivisions/DZ.yaml +809 -384
- data/lib/countries/data/subdivisions/EC.yaml +391 -192
- data/lib/countries/data/subdivisions/EE.yaml +543 -120
- data/lib/countries/data/subdivisions/EG.yaml +472 -216
- data/lib/countries/data/subdivisions/EH.yaml +24 -16
- data/lib/countries/data/subdivisions/ER.yaml +109 -48
- data/lib/countries/data/subdivisions/ES.yaml +1740 -437
- data/lib/countries/data/subdivisions/ET.yaml +207 -88
- data/lib/countries/data/subdivisions/FI.yaml +421 -37
- data/lib/countries/data/subdivisions/FJ.yaml +314 -40
- data/lib/countries/data/subdivisions/FM.yaml +63 -32
- data/lib/countries/data/subdivisions/FO.yaml +60 -54
- data/lib/countries/data/subdivisions/FR.yaml +2861 -922
- data/lib/countries/data/subdivisions/GA.yaml +159 -72
- data/lib/countries/data/subdivisions/GB.yaml +4979 -1771
- data/lib/countries/data/subdivisions/GD.yaml +114 -56
- data/lib/countries/data/subdivisions/GE.yaml +238 -96
- data/lib/countries/data/subdivisions/GF.yaml +11 -0
- data/lib/countries/data/subdivisions/GG.yaml +110 -99
- data/lib/countries/data/subdivisions/GH.yaml +266 -79
- data/lib/countries/data/subdivisions/GL.yaml +89 -0
- data/lib/countries/data/subdivisions/GM.yaml +124 -48
- data/lib/countries/data/subdivisions/GN.yaml +711 -274
- data/lib/countries/data/subdivisions/GP.yaml +11 -0
- data/lib/countries/data/subdivisions/GQ.yaml +143 -72
- data/lib/countries/data/subdivisions/GR.yaml +594 -165
- data/lib/countries/data/subdivisions/GT.yaml +351 -176
- data/lib/countries/data/subdivisions/GU.yaml +85 -58
- data/lib/countries/data/subdivisions/GW.yaml +192 -72
- data/lib/countries/data/subdivisions/GY.yaml +163 -80
- data/lib/countries/data/subdivisions/HK.yaml +86 -54
- data/lib/countries/data/subdivisions/HN.yaml +274 -144
- data/lib/countries/data/subdivisions/HR.yaml +429 -168
- data/lib/countries/data/subdivisions/HT.yaml +179 -72
- data/lib/countries/data/subdivisions/HU.yaml +791 -339
- data/lib/countries/data/subdivisions/IC.yaml +4 -0
- data/lib/countries/data/subdivisions/ID.yaml +2376 -1858
- data/lib/countries/data/subdivisions/IE.yaml +650 -259
- data/lib/countries/data/subdivisions/IL.yaml +114 -48
- data/lib/countries/data/subdivisions/IM.yaml +240 -216
- data/lib/countries/data/subdivisions/IN.yaml +1005 -298
- data/lib/countries/data/subdivisions/IQ.yaml +316 -139
- data/lib/countries/data/subdivisions/IR.yaml +596 -239
- data/lib/countries/data/subdivisions/IS.yaml +373 -67
- data/lib/countries/data/subdivisions/IT.yaml +2693 -880
- data/lib/countries/data/subdivisions/JE.yaml +120 -108
- data/lib/countries/data/subdivisions/JM.yaml +243 -112
- data/lib/countries/data/subdivisions/JO.yaml +193 -96
- data/lib/countries/data/subdivisions/JP.yaml +950 -376
- data/lib/countries/data/subdivisions/KE.yaml +807 -40
- data/lib/countries/data/subdivisions/KG.yaml +188 -64
- data/lib/countries/data/subdivisions/KH.yaml +437 -192
- data/lib/countries/data/subdivisions/KI.yaml +57 -24
- data/lib/countries/data/subdivisions/KM.yaml +49 -24
- data/lib/countries/data/subdivisions/KN.yaml +308 -112
- data/lib/countries/data/subdivisions/KP.yaml +365 -57
- data/lib/countries/data/subdivisions/KR.yaml +393 -128
- data/lib/countries/data/subdivisions/KW.yaml +87 -48
- data/lib/countries/data/subdivisions/KY.yaml +36 -24
- data/lib/countries/data/subdivisions/KZ.yaml +362 -135
- data/lib/countries/data/subdivisions/LA.yaml +300 -145
- data/lib/countries/data/subdivisions/LB.yaml +134 -48
- data/lib/countries/data/subdivisions/LC.yaml +166 -0
- data/lib/countries/data/subdivisions/LI.yaml +186 -88
- data/lib/countries/data/subdivisions/LK.yaml +544 -200
- data/lib/countries/data/subdivisions/LR.yaml +252 -110
- data/lib/countries/data/subdivisions/LS.yaml +149 -80
- data/lib/countries/data/subdivisions/LT.yaml +1042 -80
- data/lib/countries/data/subdivisions/LU.yaml +200 -17
- data/lib/countries/data/subdivisions/LV.yaml +2399 -223
- data/lib/countries/data/subdivisions/LY.yaml +339 -162
- data/lib/countries/data/subdivisions/MA.yaml +1443 -484
- data/lib/countries/data/subdivisions/MC.yaml +250 -0
- data/lib/countries/data/subdivisions/MD.yaml +638 -93
- data/lib/countries/data/subdivisions/ME.yaml +425 -168
- data/lib/countries/data/subdivisions/MF.yaml +9 -0
- data/lib/countries/data/subdivisions/MG.yaml +93 -48
- data/lib/countries/data/subdivisions/MH.yaml +422 -199
- data/lib/countries/data/subdivisions/MK.yaml +2972 -255
- data/lib/countries/data/subdivisions/ML.yaml +187 -71
- data/lib/countries/data/subdivisions/MM.yaml +287 -112
- data/lib/countries/data/subdivisions/MN.yaml +421 -176
- data/lib/countries/data/subdivisions/MO.yaml +9 -0
- data/lib/countries/data/subdivisions/MP.yaml +30 -12
- data/lib/countries/data/subdivisions/MQ.yaml +11 -0
- data/lib/countries/data/subdivisions/MR.yaml +245 -99
- data/lib/countries/data/subdivisions/MS.yaml +30 -27
- data/lib/countries/data/subdivisions/MT.yaml +1059 -544
- data/lib/countries/data/subdivisions/MU.yaml +317 -131
- data/lib/countries/data/subdivisions/MV.yaml +457 -163
- data/lib/countries/data/subdivisions/MW.yaml +537 -216
- data/lib/countries/data/subdivisions/MX.yaml +709 -256
- data/lib/countries/data/subdivisions/MY.yaml +336 -128
- data/lib/countries/data/subdivisions/MZ.yaml +191 -83
- data/lib/countries/data/subdivisions/NA.yaml +220 -107
- data/lib/countries/data/subdivisions/NC.yaml +26 -9
- data/lib/countries/data/subdivisions/NE.yaml +170 -64
- data/lib/countries/data/subdivisions/NG.yaml +870 -296
- data/lib/countries/data/subdivisions/NI.yaml +260 -136
- data/lib/countries/data/subdivisions/NL.yaml +381 -96
- data/lib/countries/data/subdivisions/NO.yaml +1087 -268
- data/lib/countries/data/subdivisions/NP.yaml +383 -112
- data/lib/countries/data/subdivisions/NR.yaml +260 -112
- data/lib/countries/data/subdivisions/NZ.yaml +318 -131
- data/lib/countries/data/subdivisions/OM.yaml +202 -52
- data/lib/countries/data/subdivisions/PA.yaml +203 -99
- data/lib/countries/data/subdivisions/PE.yaml +418 -208
- data/lib/countries/data/subdivisions/PF.yaml +30 -15
- data/lib/countries/data/subdivisions/PG.yaml +381 -155
- data/lib/countries/data/subdivisions/PH.yaml +1855 -662
- data/lib/countries/data/subdivisions/PK.yaml +185 -54
- data/lib/countries/data/subdivisions/PL.yaml +1176 -127
- data/lib/countries/data/subdivisions/PM.yaml +18 -6
- data/lib/countries/data/subdivisions/PR.yaml +326 -234
- data/lib/countries/data/subdivisions/PS.yaml +257 -0
- data/lib/countries/data/subdivisions/PT.yaml +342 -160
- data/lib/countries/data/subdivisions/PW.yaml +269 -128
- data/lib/countries/data/subdivisions/PY.yaml +321 -144
- data/lib/countries/data/subdivisions/QA.yaml +168 -65
- data/lib/countries/data/subdivisions/RE.yaml +11 -0
- data/lib/countries/data/subdivisions/RO.yaml +729 -336
- data/lib/countries/data/subdivisions/RS.yaml +589 -240
- data/lib/countries/data/subdivisions/RU.yaml +1875 -665
- data/lib/countries/data/subdivisions/RW.yaml +102 -40
- data/lib/countries/data/subdivisions/SA.yaml +234 -104
- data/lib/countries/data/subdivisions/SB.yaml +169 -80
- data/lib/countries/data/subdivisions/SC.yaml +462 -184
- data/lib/countries/data/subdivisions/SD.yaml +163 -22
- data/lib/countries/data/subdivisions/SE.yaml +435 -237
- data/lib/countries/data/subdivisions/SG.yaml +111 -19
- data/lib/countries/data/subdivisions/SH.yaml +67 -14
- data/lib/countries/data/subdivisions/SI.yaml +3570 -1549
- data/lib/countries/data/subdivisions/SJ.yaml +20 -18
- data/lib/countries/data/subdivisions/SK.yaml +129 -64
- data/lib/countries/data/subdivisions/SL.yaml +80 -31
- data/lib/countries/data/subdivisions/SM.yaml +159 -72
- data/lib/countries/data/subdivisions/SN.yaml +233 -88
- data/lib/countries/data/subdivisions/SO.yaml +311 -144
- data/lib/countries/data/subdivisions/SR.yaml +158 -80
- data/lib/countries/data/subdivisions/SS.yaml +196 -0
- data/lib/countries/data/subdivisions/ST.yaml +49 -16
- data/lib/countries/data/subdivisions/SV.yaml +231 -112
- data/lib/countries/data/subdivisions/SX.yaml +9 -0
- data/lib/countries/data/subdivisions/SY.yaml +220 -112
- data/lib/countries/data/subdivisions/SZ.yaml +65 -32
- data/lib/countries/data/subdivisions/TA.yaml +4 -0
- data/lib/countries/data/subdivisions/TD.yaml +409 -139
- data/lib/countries/data/subdivisions/TF.yaml +38 -20
- data/lib/countries/data/subdivisions/TG.yaml +75 -40
- data/lib/countries/data/subdivisions/TH.yaml +1451 -616
- data/lib/countries/data/subdivisions/TJ.yaml +100 -24
- data/lib/countries/data/subdivisions/TK.yaml +30 -27
- data/lib/countries/data/subdivisions/TL.yaml +209 -104
- data/lib/countries/data/subdivisions/TM.yaml +116 -40
- data/lib/countries/data/subdivisions/TN.yaml +412 -192
- data/lib/countries/data/subdivisions/TO.yaml +75 -40
- data/lib/countries/data/subdivisions/TR.yaml +1817 -648
- data/lib/countries/data/subdivisions/TT.yaml +296 -113
- data/lib/countries/data/subdivisions/TV.yaml +133 -59
- data/lib/countries/data/subdivisions/TW.yaml +481 -164
- data/lib/countries/data/subdivisions/TZ.yaml +661 -208
- data/lib/countries/data/subdivisions/UA.yaml +505 -216
- data/lib/countries/data/subdivisions/UG.yaml +2262 -640
- data/lib/countries/data/subdivisions/UM.yaml +216 -71
- data/lib/countries/data/subdivisions/US.yaml +1658 -464
- data/lib/countries/data/subdivisions/UY.yaml +367 -152
- data/lib/countries/data/subdivisions/UZ.yaml +289 -113
- data/lib/countries/data/subdivisions/VC.yaml +101 -48
- data/lib/countries/data/subdivisions/VE.yaml +456 -200
- data/lib/countries/data/subdivisions/VI.yaml +26 -9
- data/lib/countries/data/subdivisions/VN.yaml +3664 -2996
- data/lib/countries/data/subdivisions/VU.yaml +98 -48
- data/lib/countries/data/subdivisions/WF.yaml +73 -0
- data/lib/countries/data/subdivisions/WS.yaml +200 -88
- data/lib/countries/data/subdivisions/YE.yaml +375 -152
- data/lib/countries/data/subdivisions/YT.yaml +76 -51
- data/lib/countries/data/subdivisions/ZA.yaml +238 -72
- data/lib/countries/data/subdivisions/ZM.yaml +157 -72
- data/lib/countries/data/subdivisions/ZW.yaml +152 -73
- data/lib/countries/data/translation_corrections.yaml +10 -1
- data/lib/countries/data.rb +47 -18
- data/lib/countries/sources/cldr/downloader.rb +12 -13
- data/lib/countries/structure.rb +1 -0
- data/lib/countries/tasks/geocoding.rake +9 -16
- data/lib/countries/tasks/postal_codes.rake +48 -0
- data/lib/countries/translations.rb +1 -1
- data/lib/countries/version.rb +1 -1
- data/lib/countries.rb +0 -1
- data/spec/country_spec.rb +73 -2
- data/spec/data_spec.rb +4 -4
- data/spec/thread_safety_spec.rb +46 -0
- metadata +34 -26
- data/.travis.yml +0 -15
data/lib/countries/data.rb
CHANGED
@@ -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[
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
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
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
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
|
-
|
129
|
-
|
130
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
+
|
data/lib/countries/structure.rb
CHANGED
@@ -2,7 +2,9 @@ require 'geocoder'
|
|
2
2
|
require 'retryable'
|
3
3
|
|
4
4
|
Geocoder.configure(
|
5
|
-
|
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
|
-
|
45
|
-
|
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 = "#{
|
77
|
+
location = "#{c.alpha2}-#{code}"
|
80
78
|
|
81
|
-
|
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
|
data/lib/countries/version.rb
CHANGED
data/lib/countries.rb
CHANGED
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
|
-
|
89
|
-
expect(
|
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
|
120
|
-
CYI
|
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
|
147
|
-
LOL2
|
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:
|
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
|
-
|
10
|
+
- Pedro Moreira
|
11
|
+
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date:
|
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.
|
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.
|
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/
|
763
|
+
homepage: http://github.com/countries/countries
|
761
764
|
licenses:
|
762
765
|
- MIT
|
763
|
-
metadata:
|
764
|
-
|
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: '
|
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.
|
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
|