countries 4.2.3 → 5.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/codeql-analysis.yml +70 -0
- data/.github/workflows/tests.yml +3 -7
- data/.rubocop.yml +40 -1
- data/.rubocop_todo.yml +8 -41
- data/CHANGELOG.md +35 -2
- data/Gemfile +5 -3
- data/README.markdown +56 -62
- data/Rakefile +21 -45
- data/UPGRADE.md +39 -0
- data/bin/console +1 -0
- data/countries.gemspec +7 -6
- 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/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/zu.json +1 -1
- data/lib/countries/configuration.rb +2 -0
- data/lib/countries/country/class_methods.rb +20 -103
- data/lib/countries/country/currency_methods.rb +2 -0
- data/lib/countries/country/emoji.rb +2 -3
- data/lib/countries/country/finder_methods.rb +81 -0
- data/lib/countries/country.rb +32 -43
- data/lib/countries/data/countries/KN.yaml +0 -1
- data/lib/countries/data/subdivisions/AD.yaml +14 -7
- data/lib/countries/data/subdivisions/AE.yaml +14 -7
- data/lib/countries/data/subdivisions/AF.yaml +196 -201
- data/lib/countries/data/subdivisions/AG.yaml +16 -22
- data/lib/countries/data/subdivisions/AL.yaml +24 -12
- data/lib/countries/data/subdivisions/AM.yaml +22 -11
- data/lib/countries/data/subdivisions/AO.yaml +36 -18
- data/lib/countries/data/subdivisions/AR.yaml +48 -24
- data/lib/countries/data/subdivisions/AT.yaml +18 -9
- data/lib/countries/data/subdivisions/AU.yaml +16 -8
- data/lib/countries/data/subdivisions/AZ.yaml +434 -412
- data/lib/countries/data/subdivisions/BA.yaml +75 -223
- data/lib/countries/data/subdivisions/BB.yaml +22 -11
- data/lib/countries/data/subdivisions/BD.yaml +188 -116
- data/lib/countries/data/subdivisions/BE.yaml +174 -161
- data/lib/countries/data/subdivisions/BF.yaml +2918 -2860
- data/lib/countries/data/subdivisions/BG.yaml +56 -28
- data/lib/countries/data/subdivisions/BH.yaml +8 -21
- data/lib/countries/data/subdivisions/BI.yaml +176 -157
- data/lib/countries/data/subdivisions/BJ.yaml +24 -12
- data/lib/countries/data/subdivisions/BN.yaml +8 -4
- data/lib/countries/data/subdivisions/BO.yaml +18 -9
- data/lib/countries/data/subdivisions/BQ.yaml +6 -3
- data/lib/countries/data/subdivisions/BR.yaml +54 -27
- data/lib/countries/data/subdivisions/BS.yaml +575 -697
- data/lib/countries/data/subdivisions/BT.yaml +40 -20
- data/lib/countries/data/subdivisions/BW.yaml +337 -321
- data/lib/countries/data/subdivisions/BY.yaml +106 -116
- data/lib/countries/data/subdivisions/BZ.yaml +12 -6
- data/lib/countries/data/subdivisions/CA.yaml +26 -13
- data/lib/countries/data/subdivisions/CD.yaml +488 -525
- data/lib/countries/data/subdivisions/CF.yaml +34 -17
- data/lib/countries/data/subdivisions/CG.yaml +40 -28
- data/lib/countries/data/subdivisions/CH.yaml +52 -26
- data/lib/countries/data/subdivisions/CI.yaml +244 -516
- data/lib/countries/data/subdivisions/CL.yaml +81 -65
- data/lib/countries/data/subdivisions/CM.yaml +20 -10
- data/lib/countries/data/subdivisions/CN.yaml +2152 -2084
- data/lib/countries/data/subdivisions/CO.yaml +66 -33
- data/lib/countries/data/subdivisions/CR.yaml +14 -7
- data/lib/countries/data/subdivisions/CU.yaml +32 -16
- data/lib/countries/data/subdivisions/CV.yaml +427 -401
- data/lib/countries/data/subdivisions/CY.yaml +12 -6
- data/lib/countries/data/subdivisions/CZ.yaml +1116 -85
- data/lib/countries/data/subdivisions/DE.yaml +32 -16
- data/lib/countries/data/subdivisions/DJ.yaml +12 -6
- data/lib/countries/data/subdivisions/DK.yaml +25 -17
- data/lib/countries/data/subdivisions/DM.yaml +20 -10
- data/lib/countries/data/subdivisions/DO.yaml +84 -42
- data/lib/countries/data/subdivisions/DZ.yaml +96 -48
- data/lib/countries/data/subdivisions/EC.yaml +158 -134
- data/lib/countries/data/subdivisions/EE.yaml +501 -334
- data/lib/countries/data/subdivisions/EG.yaml +54 -27
- data/lib/countries/data/subdivisions/ER.yaml +12 -6
- data/lib/countries/data/subdivisions/ES.yaml +1459 -1390
- data/lib/countries/data/subdivisions/ET.yaml +22 -11
- data/lib/countries/data/subdivisions/FI.yaml +185 -1
- data/lib/countries/data/subdivisions/FJ.yaml +443 -424
- data/lib/countries/data/subdivisions/FM.yaml +8 -4
- data/lib/countries/data/subdivisions/FR.yaml +438 -275
- data/lib/countries/data/subdivisions/GA.yaml +18 -9
- data/lib/countries/data/subdivisions/GB.yaml +1185 -1708
- data/lib/countries/data/subdivisions/GD.yaml +14 -7
- data/lib/countries/data/subdivisions/GE.yaml +24 -12
- data/lib/countries/data/subdivisions/GH.yaml +114 -155
- data/lib/countries/data/subdivisions/GL.yaml +24 -79
- data/lib/countries/data/subdivisions/GM.yaml +12 -6
- data/lib/countries/data/subdivisions/GN.yaml +444 -403
- data/lib/countries/data/subdivisions/GQ.yaml +24 -13
- data/lib/countries/data/subdivisions/GR.yaml +114 -73
- data/lib/countries/data/subdivisions/GT.yaml +44 -22
- data/lib/countries/data/subdivisions/GW.yaml +69 -57
- data/lib/countries/data/subdivisions/GY.yaml +20 -10
- data/lib/countries/data/subdivisions/HN.yaml +36 -18
- data/lib/countries/data/subdivisions/HR.yaml +42 -21
- data/lib/countries/data/subdivisions/HT.yaml +73 -63
- data/lib/countries/data/subdivisions/HU.yaml +106 -63
- data/lib/countries/data/subdivisions/ID.yaml +229 -188
- data/lib/countries/data/subdivisions/IE.yaml +128 -97
- data/lib/countries/data/subdivisions/IL.yaml +12 -6
- data/lib/countries/data/subdivisions/IN.yaml +245 -396
- data/lib/countries/data/subdivisions/IQ.yaml +111 -91
- data/lib/countries/data/subdivisions/IR.yaml +1463 -1451
- data/lib/countries/data/subdivisions/IS.yaml +160 -25
- data/lib/countries/data/subdivisions/IT.yaml +8740 -8292
- data/lib/countries/data/subdivisions/JM.yaml +28 -14
- data/lib/countries/data/subdivisions/JO.yaml +24 -12
- data/lib/countries/data/subdivisions/JP.yaml +94 -47
- data/lib/countries/data/subdivisions/KE.yaml +95 -48
- data/lib/countries/data/subdivisions/KG.yaml +95 -86
- data/lib/countries/data/subdivisions/KH.yaml +64 -39
- data/lib/countries/data/subdivisions/KI.yaml +6 -3
- data/lib/countries/data/subdivisions/KM.yaml +6 -3
- data/lib/countries/data/subdivisions/KN.yaml +32 -16
- data/lib/countries/data/subdivisions/KP.yaml +24 -227
- data/lib/countries/data/subdivisions/KR.yaml +34 -17
- data/lib/countries/data/subdivisions/KW.yaml +12 -6
- data/lib/countries/data/subdivisions/KZ.yaml +47 -102
- data/lib/countries/data/subdivisions/LA.yaml +36 -34
- data/lib/countries/data/subdivisions/LB.yaml +71 -63
- data/lib/countries/data/subdivisions/LC.yaml +116 -106
- data/lib/countries/data/subdivisions/LI.yaml +22 -11
- data/lib/countries/data/subdivisions/LK.yaml +445 -411
- data/lib/countries/data/subdivisions/LR.yaml +146 -129
- data/lib/countries/data/subdivisions/LS.yaml +20 -10
- data/lib/countries/data/subdivisions/LT.yaml +1706 -1636
- data/lib/countries/data/subdivisions/LU.yaml +24 -12
- data/lib/countries/data/subdivisions/LV.yaml +1623 -1577
- data/lib/countries/data/subdivisions/LY.yaml +44 -22
- data/lib/countries/data/subdivisions/MA.yaml +810 -1589
- data/lib/countries/data/subdivisions/MC.yaml +261 -244
- data/lib/countries/data/subdivisions/MD.yaml +74 -79
- data/lib/countries/data/subdivisions/ME.yaml +217 -195
- data/lib/countries/data/subdivisions/MG.yaml +12 -6
- data/lib/countries/data/subdivisions/MH.yaml +167 -140
- data/lib/countries/data/subdivisions/MK.yaml +160 -80
- data/lib/countries/data/subdivisions/ML.yaml +48 -37
- data/lib/countries/data/subdivisions/MM.yaml +30 -15
- data/lib/countries/data/subdivisions/MN.yaml +44 -22
- data/lib/countries/data/subdivisions/MR.yaml +30 -34
- data/lib/countries/data/subdivisions/MT.yaml +136 -68
- data/lib/countries/data/subdivisions/MU.yaml +24 -262
- data/lib/countries/data/subdivisions/MV.yaml +161 -254
- data/lib/countries/data/subdivisions/MW.yaml +250 -219
- data/lib/countries/data/subdivisions/MX.yaml +67 -47
- data/lib/countries/data/subdivisions/MY.yaml +32 -16
- data/lib/countries/data/subdivisions/MZ.yaml +22 -11
- data/lib/countries/data/subdivisions/NA.yaml +58 -44
- data/lib/countries/data/subdivisions/NE.yaml +16 -8
- data/lib/countries/data/subdivisions/NG.yaml +74 -37
- data/lib/countries/data/subdivisions/NI.yaml +34 -17
- data/lib/countries/data/subdivisions/NL.yaml +303 -285
- data/lib/countries/data/subdivisions/NO.yaml +39 -17
- data/lib/countries/data/subdivisions/NP.yaml +302 -276
- data/lib/countries/data/subdivisions/NR.yaml +28 -14
- data/lib/countries/data/subdivisions/NZ.yaml +34 -17
- data/lib/countries/data/subdivisions/OM.yaml +260 -311
- data/lib/countries/data/subdivisions/PA.yaml +57 -44
- data/lib/countries/data/subdivisions/PE.yaml +107 -81
- data/lib/countries/data/subdivisions/PG.yaml +163 -158
- data/lib/countries/data/subdivisions/PH.yaml +5062 -4992
- data/lib/countries/data/subdivisions/PK.yaml +145 -235
- data/lib/countries/data/subdivisions/PL.yaml +51 -3
- data/lib/countries/data/subdivisions/PS.yaml +32 -16
- data/lib/countries/data/subdivisions/PT.yaml +53 -33
- data/lib/countries/data/subdivisions/PW.yaml +32 -16
- data/lib/countries/data/subdivisions/PY.yaml +36 -18
- data/lib/countries/data/subdivisions/QA.yaml +27 -78
- data/lib/countries/data/subdivisions/RO.yaml +84 -42
- data/lib/countries/data/subdivisions/RS.yaml +104 -72
- data/lib/countries/data/subdivisions/RU.yaml +166 -83
- data/lib/countries/data/subdivisions/RW.yaml +10 -5
- data/lib/countries/data/subdivisions/SA.yaml +26 -13
- data/lib/countries/data/subdivisions/SB.yaml +20 -10
- data/lib/countries/data/subdivisions/SC.yaml +54 -25
- data/lib/countries/data/subdivisions/SD.yaml +798 -780
- data/lib/countries/data/subdivisions/SE.yaml +42 -21
- data/lib/countries/data/subdivisions/SG.yaml +15 -10
- data/lib/countries/data/subdivisions/SH.yaml +21 -32
- data/lib/countries/data/subdivisions/SI.yaml +475 -263
- data/lib/countries/data/subdivisions/SK.yaml +16 -8
- data/lib/countries/data/subdivisions/SL.yaml +23 -18
- data/lib/countries/data/subdivisions/SM.yaml +18 -9
- data/lib/countries/data/subdivisions/SN.yaml +188 -174
- data/lib/countries/data/subdivisions/SO.yaml +36 -18
- data/lib/countries/data/subdivisions/SR.yaml +20 -10
- data/lib/countries/data/subdivisions/SS.yaml +20 -10
- data/lib/countries/data/subdivisions/ST.yaml +38 -52
- data/lib/countries/data/subdivisions/SV.yaml +28 -14
- data/lib/countries/data/subdivisions/SY.yaml +28 -14
- data/lib/countries/data/subdivisions/SZ.yaml +8 -4
- data/lib/countries/data/subdivisions/TD.yaml +312 -303
- data/lib/countries/data/subdivisions/TG.yaml +10 -5
- data/lib/countries/data/subdivisions/TH.yaml +211 -133
- data/lib/countries/data/subdivisions/TJ.yaml +161 -156
- data/lib/countries/data/subdivisions/TL.yaml +26 -13
- data/lib/countries/data/subdivisions/TM.yaml +12 -6
- data/lib/countries/data/subdivisions/TN.yaml +48 -24
- data/lib/countries/data/subdivisions/TO.yaml +10 -5
- data/lib/countries/data/subdivisions/TR.yaml +162 -81
- data/lib/countries/data/subdivisions/TT.yaml +128 -160
- data/lib/countries/data/subdivisions/TV.yaml +57 -63
- data/lib/countries/data/subdivisions/TW.yaml +143 -183
- data/lib/countries/data/subdivisions/TZ.yaml +62 -31
- data/lib/countries/data/subdivisions/UA.yaml +55 -28
- data/lib/countries/data/subdivisions/UG.yaml +4806 -4660
- data/lib/countries/data/subdivisions/UM.yaml +18 -9
- data/lib/countries/data/subdivisions/US.yaml +114 -57
- data/lib/countries/data/subdivisions/UY.yaml +99 -80
- data/lib/countries/data/subdivisions/UZ.yaml +28 -14
- data/lib/countries/data/subdivisions/VC.yaml +12 -6
- data/lib/countries/data/subdivisions/VE.yaml +50 -25
- data/lib/countries/data/subdivisions/VN.yaml +3576 -3513
- data/lib/countries/data/subdivisions/VU.yaml +12 -6
- data/lib/countries/data/subdivisions/WF.yaml +6 -3
- data/lib/countries/data/subdivisions/WS.yaml +22 -11
- data/lib/countries/data/subdivisions/YE.yaml +222 -200
- data/lib/countries/data/subdivisions/ZA.yaml +86 -100
- data/lib/countries/data/subdivisions/ZM.yaml +20 -10
- data/lib/countries/data/subdivisions/ZW.yaml +20 -10
- data/lib/countries/data/translations/countries-ab.yaml +254 -0
- data/lib/countries/data/translations/countries-af.yaml +254 -0
- data/lib/countries/data/translations/countries-ak.yaml +254 -0
- data/lib/countries/data/translations/countries-am.yaml +254 -0
- data/lib/countries/data/translations/countries-an.yaml +254 -0
- data/lib/countries/data/translations/countries-ar.yaml +254 -0
- data/lib/countries/data/translations/countries-as.yaml +254 -0
- data/lib/countries/data/translations/countries-ay.yaml +254 -0
- data/lib/countries/data/translations/countries-az.yaml +254 -0
- data/lib/countries/data/translations/countries-ba.yaml +254 -0
- data/lib/countries/data/translations/countries-be.yaml +254 -0
- data/lib/countries/data/translations/countries-bg.yaml +254 -0
- data/lib/countries/data/translations/countries-bi.yaml +254 -0
- data/lib/countries/data/translations/countries-bn.yaml +254 -0
- data/lib/countries/data/translations/countries-bn_IN.yaml +254 -0
- data/lib/countries/data/translations/countries-br.yaml +254 -0
- data/lib/countries/data/translations/countries-bs.yaml +254 -0
- data/lib/countries/data/translations/countries-ca.yaml +254 -0
- data/lib/countries/data/translations/countries-ce.yaml +254 -0
- data/lib/countries/data/translations/countries-ch.yaml +254 -0
- data/lib/countries/data/translations/countries-cs.yaml +254 -0
- data/lib/countries/data/translations/countries-cv.yaml +254 -0
- data/lib/countries/data/translations/countries-cy.yaml +254 -0
- data/lib/countries/data/translations/countries-da.yaml +254 -0
- data/lib/countries/data/translations/countries-de.yaml +254 -0
- data/lib/countries/data/translations/countries-dv.yaml +254 -0
- data/lib/countries/data/translations/countries-dz.yaml +254 -0
- data/lib/countries/data/translations/countries-ee.yaml +254 -0
- data/lib/countries/data/translations/countries-el.yaml +254 -0
- data/lib/countries/data/translations/countries-en.yaml +254 -0
- data/lib/countries/data/translations/countries-eo.yaml +254 -0
- data/lib/countries/data/translations/countries-es.yaml +254 -0
- data/lib/countries/data/translations/countries-et.yaml +254 -0
- data/lib/countries/data/translations/countries-eu.yaml +254 -0
- data/lib/countries/data/translations/countries-fa.yaml +254 -0
- data/lib/countries/data/translations/countries-ff.yaml +254 -0
- data/lib/countries/data/translations/countries-fi.yaml +254 -0
- data/lib/countries/data/translations/countries-fo.yaml +254 -0
- data/lib/countries/data/translations/countries-fr.yaml +254 -0
- data/lib/countries/data/translations/countries-fy.yaml +254 -0
- data/lib/countries/data/translations/countries-ga.yaml +254 -0
- data/lib/countries/data/translations/countries-gl.yaml +254 -0
- data/lib/countries/data/translations/countries-gn.yaml +254 -0
- data/lib/countries/data/translations/countries-gu.yaml +254 -0
- data/lib/countries/data/translations/countries-gv.yaml +254 -0
- data/lib/countries/data/translations/countries-ha.yaml +254 -0
- data/lib/countries/data/translations/countries-he.yaml +254 -0
- data/lib/countries/data/translations/countries-hi.yaml +254 -0
- data/lib/countries/data/translations/countries-hr.yaml +254 -0
- data/lib/countries/data/translations/countries-ht.yaml +254 -0
- data/lib/countries/data/translations/countries-hu.yaml +254 -0
- data/lib/countries/data/translations/countries-hy.yaml +254 -0
- data/lib/countries/data/translations/countries-ia.yaml +254 -0
- data/lib/countries/data/translations/countries-id.yaml +254 -0
- data/lib/countries/data/translations/countries-io.yaml +254 -0
- data/lib/countries/data/translations/countries-is.yaml +254 -0
- data/lib/countries/data/translations/countries-it.yaml +254 -0
- data/lib/countries/data/translations/countries-iu.yaml +254 -0
- data/lib/countries/data/translations/countries-ja.yaml +254 -0
- data/lib/countries/data/translations/countries-ka.yaml +254 -0
- data/lib/countries/data/translations/countries-ki.yaml +254 -0
- data/lib/countries/data/translations/countries-kk.yaml +254 -0
- data/lib/countries/data/translations/countries-kl.yaml +254 -0
- data/lib/countries/data/translations/countries-km.yaml +254 -0
- data/lib/countries/data/translations/countries-kn.yaml +254 -0
- data/lib/countries/data/translations/countries-ko.yaml +254 -0
- data/lib/countries/data/translations/countries-ku.yaml +254 -0
- data/lib/countries/data/translations/countries-kv.yaml +254 -0
- data/lib/countries/data/translations/countries-kw.yaml +254 -0
- data/lib/countries/data/translations/countries-ky.yaml +254 -0
- data/lib/countries/data/translations/countries-lo.yaml +254 -0
- data/lib/countries/data/translations/countries-lt.yaml +254 -0
- data/lib/countries/data/translations/countries-lv.yaml +254 -0
- data/lib/countries/data/translations/countries-mi.yaml +254 -0
- data/lib/countries/data/translations/countries-mk.yaml +254 -0
- data/lib/countries/data/translations/countries-ml.yaml +254 -0
- data/lib/countries/data/translations/countries-mn.yaml +254 -0
- data/lib/countries/data/translations/countries-mr.yaml +254 -0
- data/lib/countries/data/translations/countries-ms.yaml +254 -0
- data/lib/countries/data/translations/countries-mt.yaml +254 -0
- data/lib/countries/data/translations/countries-my.yaml +254 -0
- data/lib/countries/data/translations/countries-na.yaml +254 -0
- data/lib/countries/data/translations/countries-nb.yaml +254 -0
- data/lib/countries/data/translations/countries-ne.yaml +254 -0
- data/lib/countries/data/translations/countries-nl.yaml +254 -0
- data/lib/countries/data/translations/countries-nn.yaml +254 -0
- data/lib/countries/data/translations/countries-nv.yaml +254 -0
- data/lib/countries/data/translations/countries-oc.yaml +254 -0
- data/lib/countries/data/translations/countries-or.yaml +254 -0
- data/lib/countries/data/translations/countries-pa.yaml +254 -0
- data/lib/countries/data/translations/countries-pi.yaml +254 -0
- data/lib/countries/data/translations/countries-pl.yaml +254 -0
- data/lib/countries/data/translations/countries-ps.yaml +254 -0
- data/lib/countries/data/translations/countries-pt.yaml +254 -0
- data/lib/countries/data/translations/countries-pt_BR.yaml +254 -0
- data/lib/countries/data/translations/countries-ro.yaml +254 -0
- data/lib/countries/data/translations/countries-ru.yaml +254 -0
- data/lib/countries/data/translations/countries-rw.yaml +254 -0
- data/lib/countries/data/translations/countries-sc.yaml +254 -0
- data/lib/countries/data/translations/countries-sd.yaml +254 -0
- data/lib/countries/data/translations/countries-si.yaml +254 -0
- data/lib/countries/data/translations/countries-sk.yaml +254 -0
- data/lib/countries/data/translations/countries-sl.yaml +254 -0
- data/lib/countries/data/translations/countries-so.yaml +254 -0
- data/lib/countries/data/translations/countries-sq.yaml +254 -0
- data/lib/countries/data/translations/countries-sr.yaml +254 -0
- data/lib/countries/data/translations/countries-sv.yaml +254 -0
- data/lib/countries/data/translations/countries-sw.yaml +254 -0
- data/lib/countries/data/translations/countries-ta.yaml +254 -0
- data/lib/countries/data/translations/countries-te.yaml +254 -0
- data/lib/countries/data/translations/countries-tg.yaml +254 -0
- data/lib/countries/data/translations/countries-th.yaml +254 -0
- data/lib/countries/data/translations/countries-ti.yaml +254 -0
- data/lib/countries/data/translations/countries-tk.yaml +254 -0
- data/lib/countries/data/translations/countries-tl.yaml +254 -0
- data/lib/countries/data/translations/countries-tr.yaml +254 -0
- data/lib/countries/data/translations/countries-tt.yaml +254 -0
- data/lib/countries/data/translations/countries-ug.yaml +254 -0
- data/lib/countries/data/translations/countries-uk.yaml +254 -0
- data/lib/countries/data/translations/countries-ur.yaml +254 -0
- data/lib/countries/data/translations/countries-uz.yaml +254 -0
- data/lib/countries/data/translations/countries-ve.yaml +254 -0
- data/lib/countries/data/translations/countries-vi.yaml +254 -0
- data/lib/countries/data/translations/countries-wa.yaml +254 -0
- data/lib/countries/data/translations/countries-wo.yaml +254 -0
- data/lib/countries/data/translations/countries-xh.yaml +254 -0
- data/lib/countries/data/translations/countries-yo.yaml +254 -0
- data/lib/countries/data/translations/countries-zh_CN.yaml +254 -0
- data/lib/countries/data/translations/countries-zh_HK.yaml +254 -0
- data/lib/countries/data/translations/countries-zh_TW.yaml +254 -0
- data/lib/countries/data/translations/countries-zu.yaml +254 -0
- data/lib/countries/data.rb +45 -42
- data/lib/countries/global.rb +2 -0
- data/lib/countries/iso3166.rb +3 -1
- data/lib/countries/kwarg_struct.rb +2 -0
- data/lib/countries/mongoid.rb +2 -0
- data/lib/countries/sources/cldr/downloader.rb +8 -8
- data/lib/countries/sources/cldr/subdivision.rb +3 -0
- data/lib/countries/sources/cldr/subdivision_updater.rb +23 -17
- data/lib/countries/sources/local/cached_loader.rb +3 -0
- data/lib/countries/sources/local/subdivision.rb +5 -2
- data/lib/countries/sources.rb +2 -0
- data/lib/countries/structure.rb +1 -1
- data/lib/countries/subdivision.rb +21 -8
- data/lib/countries/tasks/geocoding.rake +15 -6
- data/lib/countries/tasks/postal_codes.rake +5 -3
- data/lib/countries/timezones.rb +5 -2
- data/lib/countries/translations.rb +2 -0
- data/lib/countries/version.rb +3 -1
- data/lib/countries.rb +2 -0
- data/spec/00_global_spec.rb +2 -0
- data/spec/configuration_spec.rb +11 -5
- data/spec/country_spec.rb +131 -38
- data/spec/data_spec.rb +85 -21
- data/spec/mongoid_spec.rb +2 -2
- data/spec/perf_spec.rb +16 -16
- data/spec/spec_helper.rb +2 -0
- data/spec/subdivision_spec.rb +6 -4
- data/spec/thread_safety_spec.rb +4 -3
- data/spec/timezone_spec.rb +2 -0
- metadata +146 -34
- data/lib/countries/cache/locales/zh.json +0 -1
- data/lib/countries/data/subdivisions/AI.yaml +0 -197
- data/lib/countries/data/subdivisions/BM.yaml +0 -155
- data/lib/countries/data/subdivisions/CK.yaml +0 -155
- data/lib/countries/data/subdivisions/EH.yaml +0 -80
- data/lib/countries/data/subdivisions/SJ.yaml +0 -29
- data/lib/countries/data/subdivisions/TK.yaml +0 -43
- data/lib/countries/data/translation_corrections.yaml +0 -51
- data/lib/countries/setup.rb +0 -18
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'geocoder'
|
2
4
|
require 'retryable'
|
3
5
|
|
@@ -16,7 +18,7 @@ def geocode(query, params)
|
|
16
18
|
Retryable.retryable(tries: 3, sleep: ->(n) { 2**n }) do
|
17
19
|
Geocoder.search(query, params: params).first
|
18
20
|
end
|
19
|
-
rescue => e
|
21
|
+
rescue Geocoder::Error, Geocoder::LookupTimeout => e
|
20
22
|
warn "Attempts exceeded for query #{query}, last error was #{e.message}"
|
21
23
|
nil
|
22
24
|
end
|
@@ -26,7 +28,7 @@ def load_country_yaml(alpha2)
|
|
26
28
|
end
|
27
29
|
|
28
30
|
def save_country_yaml(alpha2, data)
|
29
|
-
File.
|
31
|
+
File.write(File.join(ISO3166_ROOT_PATH, 'lib', 'countries', 'data', 'countries', "#{alpha2}.yaml"), data.to_yaml)
|
30
32
|
end
|
31
33
|
|
32
34
|
def country_codes
|
@@ -44,7 +46,10 @@ namespace :geocode do
|
|
44
46
|
data = load_country_yaml(country.alpha2)
|
45
47
|
|
46
48
|
next unless (result = geocode(country.iso_short_name, {region: country.alpha2}))
|
47
|
-
|
49
|
+
|
50
|
+
unless result.types.include?('country')
|
51
|
+
puts "WARNING:: Geocoder returned something that was not a country for #{country.alpha2}"
|
52
|
+
end
|
48
53
|
geometry = result.geometry
|
49
54
|
|
50
55
|
# Extract center point data
|
@@ -55,6 +60,7 @@ namespace :geocode do
|
|
55
60
|
|
56
61
|
# Extract bounding box data
|
57
62
|
next unless geometry['bounds']
|
63
|
+
|
58
64
|
data[code]['geo']['bounds'] = geometry['bounds']
|
59
65
|
data[code]['geo']['min_latitude'] = geometry['bounds']['southwest']['lat']
|
60
66
|
data[code]['geo']['min_longitude'] = geometry['bounds']['southwest']['lng']
|
@@ -73,10 +79,10 @@ namespace :geocode do
|
|
73
79
|
ISO3166::Country.all.select(&:subdivisions?).each do |c|
|
74
80
|
# Iterate subdivisions
|
75
81
|
state_data = c.subdivisions.dup
|
76
|
-
state_data.reject { |_, data| data['geo'] }.each do |code,
|
82
|
+
state_data.reject { |_, data| data['geo'] }.each do |code, _|
|
77
83
|
location = "#{c.alpha2}-#{code}"
|
78
84
|
|
79
|
-
next unless (result = geocode(location, {region: c.alpha2}))
|
85
|
+
next unless (result = geocode(location, { region: c.alpha2 }))
|
80
86
|
|
81
87
|
geometry = result.geometry
|
82
88
|
if geometry['location']
|
@@ -84,14 +90,17 @@ namespace :geocode do
|
|
84
90
|
state_data[code]['geo']['latitude'] = geometry['location']['lat']
|
85
91
|
state_data[code]['geo']['longitude'] = geometry['location']['lng']
|
86
92
|
end
|
93
|
+
|
87
94
|
next unless geometry['bounds']
|
95
|
+
|
88
96
|
state_data[code]['geo']['min_latitude'] = geometry['bounds']['southwest']['lat']
|
89
97
|
state_data[code]['geo']['min_longitude'] = geometry['bounds']['southwest']['lng']
|
90
98
|
state_data[code]['geo']['max_latitude'] = geometry['bounds']['northeast']['lat']
|
91
99
|
state_data[code]['geo']['max_longitude'] = geometry['bounds']['northeast']['lng']
|
92
100
|
end
|
93
101
|
# Write updated YAML for current country
|
94
|
-
File.
|
102
|
+
out = File.join(ISO3166_ROOT_PATH, 'lib', 'countries', 'data', 'subdivisions', "#{c.alpha2}.yaml")
|
103
|
+
File.write(out, state_data.to_yaml)
|
95
104
|
end
|
96
105
|
end
|
97
106
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
namespace :postal_codes do
|
2
4
|
desc 'Retrieve and update postal codes and their format'
|
3
5
|
task :update do
|
@@ -20,13 +22,13 @@ namespace :postal_codes do
|
|
20
22
|
json = JSON.parse(response) rescue {}
|
21
23
|
puts ' - Returned empty data. Skipping ' and next if json.empty?
|
22
24
|
|
23
|
-
postal_code = ['postal_code',
|
25
|
+
postal_code = ['postal_code', !json['zip'].nil?]
|
24
26
|
postal_code_format = ['postal_code_format', json['zip']]
|
25
27
|
|
26
28
|
if postal_code_index
|
27
29
|
data[postal_code_index] = postal_code
|
28
30
|
else
|
29
|
-
postal_code_index = data.find_index { |d| d[0] == 'nationality' } + 1 || data.size
|
31
|
+
postal_code_index = (data.find_index { |d| d[0] == 'nationality' } + 1) || data.size
|
30
32
|
data.insert(postal_code_index, postal_code)
|
31
33
|
end
|
32
34
|
|
@@ -42,7 +44,7 @@ namespace :postal_codes do
|
|
42
44
|
|
43
45
|
yaml[country_code] = data.to_h
|
44
46
|
|
45
|
-
File.
|
47
|
+
File.write(country_file, yaml.to_yaml)
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
data/lib/countries/timezones.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ISO3166
|
2
4
|
# Extend Country class with support for timezones. Requires the {tzinfo}[https://github.com/tzinfo/tzinfo] gem
|
3
5
|
#
|
4
6
|
# gem 'tzinfo'
|
5
7
|
#
|
6
8
|
module TimezoneExtensions
|
9
|
+
# TODO: rename method to tz_country or something similar
|
7
10
|
def timezones
|
8
|
-
@
|
11
|
+
@timezones ||= TZInfo::Country.get(alpha2)
|
9
12
|
end
|
10
13
|
end
|
11
14
|
end
|
12
15
|
|
13
|
-
ISO3166::Country.
|
16
|
+
ISO3166::Country.include ISO3166::TimezoneExtensions
|
data/lib/countries/version.rb
CHANGED
data/lib/countries.rb
CHANGED
data/spec/00_global_spec.rb
CHANGED
data/spec/configuration_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
require 'i18n'
|
4
5
|
|
@@ -16,14 +17,14 @@ describe 'ISO3166.configuration' do
|
|
16
17
|
end
|
17
18
|
|
18
19
|
it 'locales are assumed from I18n.available_locales' do
|
19
|
-
I18n.available_locales = [
|
20
|
+
I18n.available_locales = %i[de en]
|
20
21
|
ISO3166.reset
|
21
22
|
expect(ISO3166::Country.new('DE').translation(:de)).to eq 'Deutschland'
|
22
23
|
expect(ISO3166::Country.new('DE').translation(:es)).to eq nil
|
23
24
|
end
|
24
25
|
|
25
26
|
it 'unsupported locales do not affect supported locales' do
|
26
|
-
I18n.available_locales = [
|
27
|
+
I18n.available_locales = %i[de en unsupported]
|
27
28
|
ISO3166.reset
|
28
29
|
expect(ISO3166::Country.new('DE').translation(:de)).to eq 'Deutschland'
|
29
30
|
expect(ISO3166::Country.new('DE').translation(:es)).to eq nil
|
@@ -36,7 +37,7 @@ describe 'ISO3166.configuration' do
|
|
36
37
|
end
|
37
38
|
|
38
39
|
it 'locales can be changed' do
|
39
|
-
ISO3166.configuration.locales = [
|
40
|
+
ISO3166.configuration.locales = %i[es de en]
|
40
41
|
expect(ISO3166::Country.new('DE').translation(:es)).to eq 'Alemania'
|
41
42
|
expect(ISO3166::Country.new('DE').translation(:en)).to eq 'Germany'
|
42
43
|
expect(ISO3166::Country.new('DE').translation(:de)).to eq 'Deutschland'
|
@@ -44,7 +45,12 @@ describe 'ISO3166.configuration' do
|
|
44
45
|
|
45
46
|
it 'locales can be changed with a block' do
|
46
47
|
ISO3166.configure do |config|
|
47
|
-
config.locales = [
|
48
|
+
config.locales = %i[af am ar as az be bg bn br bs ca cs cy da de dz el en
|
49
|
+
eo es et eu fa fi fo fr ga gl gu he hi hr hu hy ia id
|
50
|
+
is it ja ka kk km kn ko ku lt lv mi mk ml mn mr ms mt
|
51
|
+
nb ne nl nn oc or pa pl ps pt ro ru rw si sk sl so sq
|
52
|
+
sr sv sw ta te th ti tk tl tr tt ug uk ve vi wa wo xh
|
53
|
+
zh zu]
|
48
54
|
end
|
49
55
|
|
50
56
|
expect(ISO3166::Country.new('DE').translations.size).to eq 92
|
data/spec/country_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
NUM_OF_COUNTRIES = 249
|
@@ -48,7 +48,9 @@ describe ISO3166::Country do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'should return alternate names' do
|
51
|
-
expect(country.unofficial_names).to eq(['United States', 'USA', 'Murica',
|
51
|
+
expect(country.unofficial_names).to eq(['United States', 'USA', 'Murica',
|
52
|
+
'Vereinigte Staaten von Amerika', 'États-Unis',
|
53
|
+
'Estados Unidos', 'アメリカ合衆国', 'Verenigde Staten'])
|
52
54
|
end
|
53
55
|
|
54
56
|
it 'should return translations' do
|
@@ -85,7 +87,7 @@ describe ISO3166::Country do
|
|
85
87
|
expect(country.postal_code_format).to_not be_nil
|
86
88
|
|
87
89
|
regex = Regexp.new(country.postal_code_format)
|
88
|
-
expect(regex).to match(
|
90
|
+
expect(regex).to match('12345-6789')
|
89
91
|
|
90
92
|
antarctica = ISO3166::Country.search('AQ')
|
91
93
|
expect(antarctica.postal_code_format).to be_nil
|
@@ -123,7 +125,7 @@ describe ISO3166::Country do
|
|
123
125
|
let(:country) { ISO3166::Country.search('BE') }
|
124
126
|
|
125
127
|
it 'should return its local names based on its languages' do
|
126
|
-
expect(country.local_names).to match_array(%w
|
128
|
+
expect(country.local_names).to match_array(%w[België Belgique Belgien])
|
127
129
|
end
|
128
130
|
|
129
131
|
it 'should return its first local name' do
|
@@ -219,7 +221,7 @@ describe ISO3166::Country do
|
|
219
221
|
end
|
220
222
|
|
221
223
|
describe 'subdivisions' do
|
222
|
-
let(:virginia) { country.
|
224
|
+
let(:virginia) { country.subdivisions['VA'] }
|
223
225
|
it 'should return an empty hash for a country with no ISO3166-2' do
|
224
226
|
expect(ISO3166::Country.search('VA').subdivisions.size).to eq(0)
|
225
227
|
end
|
@@ -228,8 +230,8 @@ describe ISO3166::Country do
|
|
228
230
|
expect(country.subdivisions.size).to eq(57)
|
229
231
|
end
|
230
232
|
|
231
|
-
it 'should be
|
232
|
-
expect
|
233
|
+
it '#states should be deprecated' do
|
234
|
+
expect {country.states}.to output.to_stderr
|
233
235
|
end
|
234
236
|
|
235
237
|
it 'should be a subdivision object' do
|
@@ -249,6 +251,60 @@ describe ISO3166::Country do
|
|
249
251
|
end
|
250
252
|
end
|
251
253
|
|
254
|
+
describe 'subdivision_types' do
|
255
|
+
it "should return an array of subdivision types" do
|
256
|
+
expect(country.subdivision_types).to contain_exactly('district', 'state', 'outlying_area')
|
257
|
+
end
|
258
|
+
|
259
|
+
it "should return an array of subdivision types even if there is only a single type" do
|
260
|
+
expect(ISO3166::Country['LI'].subdivision_types).to contain_exactly('commune')
|
261
|
+
end
|
262
|
+
|
263
|
+
it "should return an empty array if country has no subdivisions" do
|
264
|
+
expect(ISO3166::Country['AS'].subdivisions?).to be_falsey
|
265
|
+
expect(ISO3166::Country['AS'].subdivision_types).to eq([])
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
describe 'subdivisions_of_types' do
|
270
|
+
it "given a single type, should return an array of subdivisions that match the type" do
|
271
|
+
us_states = country.subdivisions_of_types(%w[state])
|
272
|
+
expect(us_states.size).to eq(50)
|
273
|
+
dc = country.subdivisions_of_types(%w[district])
|
274
|
+
expect(dc.size).to eq(1)
|
275
|
+
end
|
276
|
+
|
277
|
+
it "given multiple types, should return an array of subdivisions matching the types" do
|
278
|
+
us_states_plus_dc = country.subdivisions_of_types(%w[state district])
|
279
|
+
expect(us_states_plus_dc.size).to eq(51)
|
280
|
+
end
|
281
|
+
|
282
|
+
it "given multiple types where at least one does not exist for that country, should work without issue" do
|
283
|
+
us_states_plus_dc = country.subdivisions_of_types(%w[state district governorate])
|
284
|
+
expect(us_states_plus_dc.size).to eq(51)
|
285
|
+
end
|
286
|
+
|
287
|
+
it "given only types that do not exist for that country, should return an empty collection" do
|
288
|
+
should_be_empty = ISO3166::Country['PT'].subdivisions_of_types(%w[state county])
|
289
|
+
expect(should_be_empty).to be_empty
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
describe 'humanized_subdivision_types' do
|
294
|
+
it "should return an array of humanized subdivision types" do
|
295
|
+
expect(country.humanized_subdivision_types).to contain_exactly('District', 'State', 'Outlying area')
|
296
|
+
end
|
297
|
+
|
298
|
+
it "should return an array of subdivision types even if there is only a single type" do
|
299
|
+
expect(ISO3166::Country['LI'].humanized_subdivision_types).to contain_exactly('Commune')
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should return an empty array if country has no subdivisions" do
|
303
|
+
expect(ISO3166::Country['AS'].subdivisions?).to be_falsey
|
304
|
+
expect(ISO3166::Country['AS'].humanized_subdivision_types).to eq([])
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
252
308
|
describe 'subdivision_names_with_codes' do
|
253
309
|
it 'should return an alphabetized list of all subdivisions names with codes' do
|
254
310
|
subdivisions = ISO3166::Country.search('EG').subdivision_names_with_codes
|
@@ -259,7 +315,7 @@ describe ISO3166::Country do
|
|
259
315
|
end
|
260
316
|
|
261
317
|
it 'should return an alphabetized list of subdivision names translated to current locale with codes' do
|
262
|
-
ISO3166.configuration.locales = [
|
318
|
+
ISO3166.configuration.locales = %i[es de en]
|
263
319
|
|
264
320
|
subdivisions = ISO3166::Country.search('EG').subdivision_names_with_codes(:es)
|
265
321
|
expect(subdivisions).to be_an(Array)
|
@@ -328,7 +384,7 @@ describe ISO3166::Country do
|
|
328
384
|
countries = ISO3166::Country.all_translated('fr')
|
329
385
|
expect(countries).to be_an(Array)
|
330
386
|
expect(countries.first).to be_a(String)
|
331
|
-
expect(countries.first).to eq('
|
387
|
+
expect(countries.first).to eq('Andorre')
|
332
388
|
# countries missing the desired locale will not be added to the list
|
333
389
|
# so all 250 countries may not be returned, 'fr' returns 249, for example
|
334
390
|
expect(countries.size).to eq(NUM_OF_COUNTRIES)
|
@@ -338,7 +394,7 @@ describe ISO3166::Country do
|
|
338
394
|
countries = ISO3166::Country.all_translated
|
339
395
|
expect(countries).to be_an(Array)
|
340
396
|
expect(countries.first).to be_a(String)
|
341
|
-
expect(countries.first).to eq('
|
397
|
+
expect(countries.first).to eq('Andorra')
|
342
398
|
expect(countries.size).to eq(NUM_OF_COUNTRIES)
|
343
399
|
end
|
344
400
|
|
@@ -371,11 +427,11 @@ describe ISO3166::Country do
|
|
371
427
|
expect(countries.first[0]).to be_a(String)
|
372
428
|
expect(countries.first[0]).to eq('Afghanistan')
|
373
429
|
expect(countries.size).to eq(NUM_OF_COUNTRIES)
|
374
|
-
expect(countries.any?{|pair| !pair[0].html_safe?}).to eq(false)
|
430
|
+
expect(countries.any? { |pair| !pair[0].html_safe? }).to eq(false)
|
375
431
|
end
|
376
432
|
|
377
433
|
it 'should return an alphabetized list of all country names translated to current locale with ISOCODE alpha2' do
|
378
|
-
ISO3166.configuration.locales = [
|
434
|
+
ISO3166.configuration.locales = %i[es de en]
|
379
435
|
|
380
436
|
countries = ISO3166::Country.all_names_with_codes(:es)
|
381
437
|
expect(countries).to be_an(Array)
|
@@ -395,7 +451,7 @@ describe ISO3166::Country do
|
|
395
451
|
end
|
396
452
|
|
397
453
|
it 'should return an alphabetized list of all country names translated to current locale with ISOCODE alpha2' do
|
398
|
-
ISO3166.configuration.locales = [
|
454
|
+
ISO3166.configuration.locales = %i[es de en]
|
399
455
|
|
400
456
|
countries = ISO3166::Country.all_names_with_codes(:es)
|
401
457
|
expect(countries).to be_an(Array)
|
@@ -407,7 +463,7 @@ describe ISO3166::Country do
|
|
407
463
|
|
408
464
|
describe 'translation' do
|
409
465
|
it 'should return the localized name for a country to the selected locale' do
|
410
|
-
ISO3166.configuration.locales = [
|
466
|
+
ISO3166.configuration.locales = %i[es de en]
|
411
467
|
countries = ISO3166::Country.new(:de).translation('de')
|
412
468
|
expect(countries).to be_an(String)
|
413
469
|
expect(countries).to eq('Deutschland')
|
@@ -426,7 +482,7 @@ describe ISO3166::Country do
|
|
426
482
|
|
427
483
|
context 'should return variant locales' do
|
428
484
|
it 'should return different value for Chinese variants' do
|
429
|
-
ISO3166.configuration.locales = [
|
485
|
+
ISO3166.configuration.locales = %i[zh-cn zh-hk zh-tw]
|
430
486
|
name_cn = ISO3166::Country['TW'].translation('zh-cn')
|
431
487
|
name_hk = ISO3166::Country['TW'].translation('zh-hk')
|
432
488
|
name_tw = ISO3166::Country['TW'].translation('zh-tw')
|
@@ -434,7 +490,7 @@ describe ISO3166::Country do
|
|
434
490
|
end
|
435
491
|
|
436
492
|
it 'should return different value for Portuguese variants' do
|
437
|
-
ISO3166.configuration.locales = [
|
493
|
+
ISO3166.configuration.locales = %i[pt pt-br]
|
438
494
|
name_pt = ISO3166::Country['SG'].translation('pt')
|
439
495
|
name_br = ISO3166::Country['SG'].translation('pt-br')
|
440
496
|
expect([name_pt, name_br].uniq.size).to eql 2
|
@@ -446,8 +502,8 @@ describe ISO3166::Country do
|
|
446
502
|
it 'should return an hash of all country names translated to the selected locale' do
|
447
503
|
countries = ISO3166::Country.translations('fr')
|
448
504
|
expect(countries).to be_an(Hash)
|
449
|
-
expect(countries.first[0]).to eq('
|
450
|
-
expect(countries.first).to eq(%w
|
505
|
+
expect(countries.first[0]).to eq('AD')
|
506
|
+
expect(countries.first).to eq(%w[AD Andorre])
|
451
507
|
# countries missing the desired locale will not be added to the list
|
452
508
|
# so all 250 countries may not be returned, 'fr' returns 249, for example
|
453
509
|
expect(countries.size).to eq(NUM_OF_COUNTRIES)
|
@@ -456,8 +512,8 @@ describe ISO3166::Country do
|
|
456
512
|
it 'should return an hash of all country names in English if no locale is passed' do
|
457
513
|
countries = ISO3166::Country.translations
|
458
514
|
expect(countries).to be_an(Hash)
|
459
|
-
expect(countries.first[0]).to eq('
|
460
|
-
expect(countries.first).to eq(%w
|
515
|
+
expect(countries.first[0]).to eq('AD')
|
516
|
+
expect(countries.first).to eq(%w[AD Andorra])
|
461
517
|
expect(countries.size).to eq(NUM_OF_COUNTRIES)
|
462
518
|
end
|
463
519
|
end
|
@@ -648,7 +704,9 @@ describe ISO3166::Country do
|
|
648
704
|
|
649
705
|
context 'when finding by invalid attribute' do
|
650
706
|
it 'should raise an error' do
|
651
|
-
expect { ISO3166::Country.find_by_invalid('invalid') }.to
|
707
|
+
expect { ISO3166::Country.find_by_invalid('invalid') }.to(
|
708
|
+
raise_error(RuntimeError, "Invalid attribute name 'invalid'")
|
709
|
+
)
|
652
710
|
end
|
653
711
|
end
|
654
712
|
|
@@ -713,6 +771,49 @@ describe ISO3166::Country do
|
|
713
771
|
end
|
714
772
|
end
|
715
773
|
|
774
|
+
describe '#find_country_by_any_name' do
|
775
|
+
context 'when search name found' do
|
776
|
+
let(:uk) { ISO3166::Country.find_country_by_any_name('United Kingdom') }
|
777
|
+
|
778
|
+
it 'should be a country instance' do
|
779
|
+
expect(uk).to be_a(ISO3166::Country)
|
780
|
+
expect(uk.alpha2).to eq('GB')
|
781
|
+
end
|
782
|
+
end
|
783
|
+
|
784
|
+
context 'when search lowercase name found' do
|
785
|
+
let(:uk) { ISO3166::Country.find_country_by_any_name('united kingdom') }
|
786
|
+
|
787
|
+
it 'should be a country instance' do
|
788
|
+
expect(uk).to be_a(ISO3166::Country)
|
789
|
+
expect(uk.alpha2).to eq('GB')
|
790
|
+
end
|
791
|
+
end
|
792
|
+
|
793
|
+
context 'when the search term contains comma' do
|
794
|
+
let(:korea) { ISO3166::Country.find_country_by_any_name('Korea, Republic of') }
|
795
|
+
|
796
|
+
it 'should be a country instance' do
|
797
|
+
expect(korea).to be_a(ISO3166::Country)
|
798
|
+
expect(korea.alpha2).to eq('KR')
|
799
|
+
end
|
800
|
+
end
|
801
|
+
|
802
|
+
context 'when search translation found' do
|
803
|
+
before do
|
804
|
+
ISO3166.configure do |config|
|
805
|
+
config.locales = [:bs]
|
806
|
+
end
|
807
|
+
end
|
808
|
+
let(:uk) { ISO3166::Country.find_country_by_any_name('Velika Britanija') }
|
809
|
+
|
810
|
+
it 'should be a country instance' do
|
811
|
+
expect(uk).to be_a(ISO3166::Country)
|
812
|
+
expect(uk.alpha2).to eq('GB')
|
813
|
+
end
|
814
|
+
end
|
815
|
+
end
|
816
|
+
|
716
817
|
context 'regression test for #388' do
|
717
818
|
let(:no_country) { ISO3166::Country.find_country_by_translated_names(nil) }
|
718
819
|
|
@@ -729,6 +830,7 @@ describe ISO3166::Country do
|
|
729
830
|
expect { uk }.to raise_error(RuntimeError)
|
730
831
|
end
|
731
832
|
end
|
833
|
+
|
732
834
|
context 'when search name not found' do
|
733
835
|
let(:bogus) { ISO3166::Country.find_country_by_unofficial_names('Does not exist') }
|
734
836
|
|
@@ -785,8 +887,9 @@ describe ISO3166::Country do
|
|
785
887
|
|
786
888
|
context 'when finding by invalid attribute' do
|
787
889
|
it 'should raise an error' do
|
788
|
-
expect { ISO3166::Country.find_country_by_invalid('invalid') }.to
|
789
|
-
|
890
|
+
expect { ISO3166::Country.find_country_by_invalid('invalid') }.to(
|
891
|
+
raise_error(RuntimeError, "Invalid attribute name 'invalid'")
|
892
|
+
)
|
790
893
|
end
|
791
894
|
end
|
792
895
|
|
@@ -847,16 +950,6 @@ describe ISO3166::Country do
|
|
847
950
|
end
|
848
951
|
end
|
849
952
|
|
850
|
-
describe 'names in Data' do
|
851
|
-
it 'should be unique (to allow .find_by_name work properly)' do
|
852
|
-
names = ISO3166::Data.cache.map do |_k, v|
|
853
|
-
[v['iso_short_name'], v['unofficial_names']].flatten.uniq
|
854
|
-
end.flatten
|
855
|
-
|
856
|
-
expect(names.size).to eq(names.uniq.size)
|
857
|
-
end
|
858
|
-
end
|
859
|
-
|
860
953
|
describe 'Norway' do
|
861
954
|
let(:norway) { ISO3166::Country.search('NO') }
|
862
955
|
|
@@ -947,7 +1040,7 @@ describe ISO3166::Country do
|
|
947
1040
|
|
948
1041
|
it 'should contain all keys for vat_rates' do
|
949
1042
|
expect(belgium.vat_rates).to be_a(Hash)
|
950
|
-
expect(belgium.vat_rates.keys).to eq(%w
|
1043
|
+
expect(belgium.vat_rates.keys).to eq(%w[standard reduced super_reduced parking])
|
951
1044
|
end
|
952
1045
|
|
953
1046
|
it 'should return an array of reduced vat rates' do
|
@@ -1021,7 +1114,7 @@ describe ISO3166::Country do
|
|
1021
1114
|
|
1022
1115
|
subject { ISO3166::Country.pluck(*args) }
|
1023
1116
|
|
1024
|
-
it
|
1117
|
+
it 'returns empty arrays' do
|
1025
1118
|
expect(subject.first).to be_empty
|
1026
1119
|
expect(subject.last).to be_empty
|
1027
1120
|
end
|
@@ -1029,9 +1122,9 @@ describe ISO3166::Country do
|
|
1029
1122
|
context "when asking for alpha2, alpha3 and iso_short_name" do
|
1030
1123
|
let(:args) { [:alpha2, :alpha3, :iso_short_name] }
|
1031
1124
|
|
1032
|
-
it
|
1033
|
-
expect(subject.first).to eq([
|
1034
|
-
expect(subject.last).to eq([
|
1125
|
+
it 'returns the correct values' do
|
1126
|
+
expect(subject.first).to eq(%w[AD AND Andorra])
|
1127
|
+
expect(subject.last).to eq(%w[ZW ZWE Zimbabwe])
|
1035
1128
|
end
|
1036
1129
|
end
|
1037
1130
|
end
|