countries 5.4.0 → 5.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (250) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +61 -0
  3. data/.github/workflows/tests.yml +4 -0
  4. data/.gitignore +0 -1
  5. data/.rubocop.yml +17 -8
  6. data/CHANGELOG.md +8 -0
  7. data/Gemfile +1 -2
  8. data/Gemfile.lock +84 -0
  9. data/README.md +41 -1
  10. data/Rakefile +2 -3
  11. data/countries.gemspec +1 -1
  12. data/lib/countries/cache/countries.json +1 -1
  13. data/lib/countries/country/class_methods.rb +22 -3
  14. data/lib/countries/country/country_subdivision_methods.rb +82 -0
  15. data/lib/countries/country/currency_methods.rb +0 -1
  16. data/lib/countries/country/finder_methods.rb +2 -4
  17. data/lib/countries/country.rb +13 -53
  18. data/lib/countries/data/countries/AR.yaml +1 -0
  19. data/lib/countries/data/countries/AU.yaml +1 -0
  20. data/lib/countries/data/countries/BR.yaml +1 -0
  21. data/lib/countries/data/countries/CA.yaml +2 -0
  22. data/lib/countries/data/countries/CN.yaml +1 -0
  23. data/lib/countries/data/countries/DE.yaml +2 -0
  24. data/lib/countries/data/countries/FR.yaml +2 -0
  25. data/lib/countries/data/countries/GB.yaml +2 -0
  26. data/lib/countries/data/countries/ID.yaml +1 -0
  27. data/lib/countries/data/countries/IN.yaml +1 -0
  28. data/lib/countries/data/countries/IT.yaml +2 -0
  29. data/lib/countries/data/countries/JP.yaml +2 -0
  30. data/lib/countries/data/countries/KR.yaml +1 -0
  31. data/lib/countries/data/countries/MX.yaml +1 -0
  32. data/lib/countries/data/countries/RU.yaml +1 -0
  33. data/lib/countries/data/countries/SA.yaml +1 -0
  34. data/lib/countries/data/countries/TR.yaml +1 -0
  35. data/lib/countries/data/countries/US.yaml +2 -0
  36. data/lib/countries/data/countries/ZA.yaml +1 -0
  37. data/lib/countries/data/locales_methods.rb +23 -0
  38. data/lib/countries/data/subdivision_methods.rb +30 -0
  39. data/lib/countries/data/subdivisions/AD.yaml +7 -0
  40. data/lib/countries/data/subdivisions/AE.yaml +18 -0
  41. data/lib/countries/data/subdivisions/AF.yaml +167 -2
  42. data/lib/countries/data/subdivisions/AG.yaml +9 -0
  43. data/lib/countries/data/subdivisions/AL.yaml +57 -0
  44. data/lib/countries/data/subdivisions/AM.yaml +34 -0
  45. data/lib/countries/data/subdivisions/AO.yaml +36 -0
  46. data/lib/countries/data/subdivisions/AR.yaml +46 -0
  47. data/lib/countries/data/subdivisions/AT.yaml +28 -0
  48. data/lib/countries/data/subdivisions/AU.yaml +29 -0
  49. data/lib/countries/data/subdivisions/AZ.yaml +239 -0
  50. data/lib/countries/data/subdivisions/BA.yaml +5 -0
  51. data/lib/countries/data/subdivisions/BB.yaml +4 -0
  52. data/lib/countries/data/subdivisions/BD.yaml +139 -0
  53. data/lib/countries/data/subdivisions/BE.yaml +34 -0
  54. data/lib/countries/data/subdivisions/BF.yaml +56 -0
  55. data/lib/countries/data/subdivisions/BG.yaml +30 -0
  56. data/lib/countries/data/subdivisions/BH.yaml +13 -0
  57. data/lib/countries/data/subdivisions/BI.yaml +54 -0
  58. data/lib/countries/data/subdivisions/BJ.yaml +22 -0
  59. data/lib/countries/data/subdivisions/BN.yaml +9 -0
  60. data/lib/countries/data/subdivisions/BO.yaml +35 -0
  61. data/lib/countries/data/subdivisions/BQ.yaml +4 -0
  62. data/lib/countries/data/subdivisions/BR.yaml +14 -0
  63. data/lib/countries/data/subdivisions/BS.yaml +24 -0
  64. data/lib/countries/data/subdivisions/BT.yaml +24 -0
  65. data/lib/countries/data/subdivisions/BW.yaml +24 -0
  66. data/lib/countries/data/subdivisions/BY.yaml +5 -0
  67. data/lib/countries/data/subdivisions/BZ.yaml +3 -0
  68. data/lib/countries/data/subdivisions/CA.yaml +24 -0
  69. data/lib/countries/data/subdivisions/CD.yaml +77 -0
  70. data/lib/countries/data/subdivisions/CF.yaml +15 -0
  71. data/lib/countries/data/subdivisions/CG.yaml +18 -0
  72. data/lib/countries/data/subdivisions/CH.yaml +92 -0
  73. data/lib/countries/data/subdivisions/CI.yaml +65 -0
  74. data/lib/countries/data/subdivisions/CL.yaml +45 -2
  75. data/lib/countries/data/subdivisions/CM.yaml +22 -0
  76. data/lib/countries/data/subdivisions/CN.yaml +98 -0
  77. data/lib/countries/data/subdivisions/CO.yaml +68 -0
  78. data/lib/countries/data/subdivisions/CR.yaml +14 -0
  79. data/lib/countries/data/subdivisions/CU.yaml +42 -0
  80. data/lib/countries/data/subdivisions/CV.yaml +32 -0
  81. data/lib/countries/data/subdivisions/CY.yaml +18 -0
  82. data/lib/countries/data/subdivisions/CZ.yaml +227 -0
  83. data/lib/countries/data/subdivisions/DE.yaml +31 -0
  84. data/lib/countries/data/subdivisions/DJ.yaml +16 -0
  85. data/lib/countries/data/subdivisions/DK.yaml +13 -0
  86. data/lib/countries/data/subdivisions/DM.yaml +1 -0
  87. data/lib/countries/data/subdivisions/DO.yaml +102 -0
  88. data/lib/countries/data/subdivisions/DZ.yaml +104 -0
  89. data/lib/countries/data/subdivisions/EC.yaml +72 -0
  90. data/lib/countries/data/subdivisions/EE.yaml +6 -0
  91. data/lib/countries/data/subdivisions/EG.yaml +54 -0
  92. data/lib/countries/data/subdivisions/ER.yaml +2 -0
  93. data/lib/countries/data/subdivisions/ES.yaml +252 -0
  94. data/lib/countries/data/subdivisions/ET.yaml +27 -0
  95. data/lib/countries/data/subdivisions/FI.yaml +78 -0
  96. data/lib/countries/data/subdivisions/FJ.yaml +30 -0
  97. data/lib/countries/data/subdivisions/FM.yaml +11 -0
  98. data/lib/countries/data/subdivisions/FR.yaml +332 -1
  99. data/lib/countries/data/subdivisions/GA.yaml +24 -0
  100. data/lib/countries/data/subdivisions/GB.yaml +488 -0
  101. data/lib/countries/data/subdivisions/GD.yaml +10 -0
  102. data/lib/countries/data/subdivisions/GE.yaml +34 -0
  103. data/lib/countries/data/subdivisions/GH.yaml +79 -0
  104. data/lib/countries/data/subdivisions/GL.yaml +58 -0
  105. data/lib/countries/data/subdivisions/GM.yaml +10 -0
  106. data/lib/countries/data/subdivisions/GN.yaml +65 -0
  107. data/lib/countries/data/subdivisions/GQ.yaml +36 -0
  108. data/lib/countries/data/subdivisions/GR.yaml +41 -0
  109. data/lib/countries/data/subdivisions/GW.yaml +24 -0
  110. data/lib/countries/data/subdivisions/GY.yaml +31 -0
  111. data/lib/countries/data/subdivisions/HN.yaml +21 -0
  112. data/lib/countries/data/subdivisions/HR.yaml +82 -0
  113. data/lib/countries/data/subdivisions/HT.yaml +14 -0
  114. data/lib/countries/data/subdivisions/HU.yaml +94 -0
  115. data/lib/countries/data/subdivisions/ID.yaml +99 -0
  116. data/lib/countries/data/subdivisions/IE.yaml +39 -0
  117. data/lib/countries/data/subdivisions/IL.yaml +15 -0
  118. data/lib/countries/data/subdivisions/IN.yaml +210 -0
  119. data/lib/countries/data/subdivisions/IQ.yaml +59 -0
  120. data/lib/countries/data/subdivisions/IR.yaml +2 -0
  121. data/lib/countries/data/subdivisions/IS.yaml +560 -0
  122. data/lib/countries/data/subdivisions/IT.yaml +321 -0
  123. data/lib/countries/data/subdivisions/JM.yaml +22 -0
  124. data/lib/countries/data/subdivisions/JO.yaml +16 -0
  125. data/lib/countries/data/subdivisions/JP.yaml +42 -0
  126. data/lib/countries/data/subdivisions/KE.yaml +298 -0
  127. data/lib/countries/data/subdivisions/KG.yaml +28 -0
  128. data/lib/countries/data/subdivisions/KH.yaml +108 -0
  129. data/lib/countries/data/subdivisions/KI.yaml +6 -0
  130. data/lib/countries/data/subdivisions/KM.yaml +4 -0
  131. data/lib/countries/data/subdivisions/KN.yaml +6 -0
  132. data/lib/countries/data/subdivisions/KP.yaml +42 -0
  133. data/lib/countries/data/subdivisions/KR.yaml +36 -0
  134. data/lib/countries/data/subdivisions/KW.yaml +5 -0
  135. data/lib/countries/data/subdivisions/KZ.yaml +113 -0
  136. data/lib/countries/data/subdivisions/LA.yaml +49 -0
  137. data/lib/countries/data/subdivisions/LB.yaml +28 -0
  138. data/lib/countries/data/subdivisions/LC.yaml +6 -0
  139. data/lib/countries/data/subdivisions/LI.yaml +37 -0
  140. data/lib/countries/data/subdivisions/LK.yaml +67 -0
  141. data/lib/countries/data/subdivisions/LR.yaml +16 -0
  142. data/lib/countries/data/subdivisions/LS.yaml +23 -0
  143. data/lib/countries/data/subdivisions/LT.yaml +315 -0
  144. data/lib/countries/data/subdivisions/LU.yaml +31 -0
  145. data/lib/countries/data/subdivisions/LV.yaml +83 -0
  146. data/lib/countries/data/subdivisions/LY.yaml +16 -0
  147. data/lib/countries/data/subdivisions/MA.yaml +827 -12
  148. data/lib/countries/data/subdivisions/MC.yaml +47 -0
  149. data/lib/countries/data/subdivisions/MD.yaml +41 -0
  150. data/lib/countries/data/subdivisions/ME.yaml +83 -0
  151. data/lib/countries/data/subdivisions/MG.yaml +21 -0
  152. data/lib/countries/data/subdivisions/MH.yaml +70 -0
  153. data/lib/countries/data/subdivisions/MK.yaml +505 -0
  154. data/lib/countries/data/subdivisions/ML.yaml +33 -0
  155. data/lib/countries/data/subdivisions/MM.yaml +51 -0
  156. data/lib/countries/data/subdivisions/MN.yaml +94 -0
  157. data/lib/countries/data/subdivisions/MR.yaml +32 -0
  158. data/lib/countries/data/subdivisions/MT.yaml +126 -0
  159. data/lib/countries/data/subdivisions/MU.yaml +21 -0
  160. data/lib/countries/data/subdivisions/MV.yaml +20 -0
  161. data/lib/countries/data/subdivisions/MW.yaml +52 -0
  162. data/lib/countries/data/subdivisions/MX.yaml +23 -0
  163. data/lib/countries/data/subdivisions/MY.yaml +24 -0
  164. data/lib/countries/data/subdivisions/MZ.yaml +20 -0
  165. data/lib/countries/data/subdivisions/NA.yaml +28 -0
  166. data/lib/countries/data/subdivisions/NE.yaml +9 -0
  167. data/lib/countries/data/subdivisions/NG.yaml +89 -0
  168. data/lib/countries/data/subdivisions/NI.yaml +25 -0
  169. data/lib/countries/data/subdivisions/NL.yaml +24 -0
  170. data/lib/countries/data/subdivisions/NO.yaml +138 -1
  171. data/lib/countries/data/subdivisions/NP.yaml +9 -0
  172. data/lib/countries/data/subdivisions/NR.yaml +19 -0
  173. data/lib/countries/data/subdivisions/NZ.yaml +34 -0
  174. data/lib/countries/data/subdivisions/OM.yaml +10 -0
  175. data/lib/countries/data/subdivisions/PA.yaml +27 -0
  176. data/lib/countries/data/subdivisions/PE.yaml +24 -0
  177. data/lib/countries/data/subdivisions/PG.yaml +46 -0
  178. data/lib/countries/data/subdivisions/PH.yaml +293 -0
  179. data/lib/countries/data/subdivisions/PK.yaml +22 -0
  180. data/lib/countries/data/subdivisions/PL.yaml +141 -0
  181. data/lib/countries/data/subdivisions/PS.yaml +41 -0
  182. data/lib/countries/data/subdivisions/PT.yaml +36 -0
  183. data/lib/countries/data/subdivisions/PW.yaml +24 -0
  184. data/lib/countries/data/subdivisions/PY.yaml +21 -0
  185. data/lib/countries/data/subdivisions/QA.yaml +26 -0
  186. data/lib/countries/data/subdivisions/RO.yaml +189 -0
  187. data/lib/countries/data/subdivisions/RS.yaml +112 -0
  188. data/lib/countries/data/subdivisions/RU.yaml +123 -0
  189. data/lib/countries/data/subdivisions/RW.yaml +7 -0
  190. data/lib/countries/data/subdivisions/SA.yaml +38 -0
  191. data/lib/countries/data/subdivisions/SB.yaml +11 -0
  192. data/lib/countries/data/subdivisions/SC.yaml +45 -0
  193. data/lib/countries/data/subdivisions/SD.yaml +15 -0
  194. data/lib/countries/data/subdivisions/SE.yaml +42 -0
  195. data/lib/countries/data/subdivisions/SG.yaml +8 -0
  196. data/lib/countries/data/subdivisions/SH.yaml +6 -0
  197. data/lib/countries/data/subdivisions/SI.yaml +735 -0
  198. data/lib/countries/data/subdivisions/SK.yaml +22 -0
  199. data/lib/countries/data/subdivisions/SL.yaml +7 -0
  200. data/lib/countries/data/subdivisions/SM.yaml +19 -0
  201. data/lib/countries/data/subdivisions/SN.yaml +43 -0
  202. data/lib/countries/data/subdivisions/SO.yaml +71 -0
  203. data/lib/countries/data/subdivisions/SR.yaml +17 -0
  204. data/lib/countries/data/subdivisions/SS.yaml +4 -0
  205. data/lib/countries/data/subdivisions/ST.yaml +127 -0
  206. data/lib/countries/data/subdivisions/SV.yaml +20 -0
  207. data/lib/countries/data/subdivisions/SY.yaml +53 -0
  208. data/lib/countries/data/subdivisions/SZ.yaml +18 -0
  209. data/lib/countries/data/subdivisions/TD.yaml +51 -0
  210. data/lib/countries/data/subdivisions/TG.yaml +13 -0
  211. data/lib/countries/data/subdivisions/TH.yaml +231 -0
  212. data/lib/countries/data/subdivisions/TJ.yaml +15 -0
  213. data/lib/countries/data/subdivisions/TL.yaml +38 -0
  214. data/lib/countries/data/subdivisions/TM.yaml +15 -0
  215. data/lib/countries/data/subdivisions/TN.yaml +25 -0
  216. data/lib/countries/data/subdivisions/TO.yaml +1 -0
  217. data/lib/countries/data/subdivisions/TR.yaml +93 -0
  218. data/lib/countries/data/subdivisions/TT.yaml +25 -0
  219. data/lib/countries/data/subdivisions/TV.yaml +25 -0
  220. data/lib/countries/data/subdivisions/TW.yaml +106 -0
  221. data/lib/countries/data/subdivisions/TZ.yaml +38 -0
  222. data/lib/countries/data/subdivisions/UA.yaml +86 -4
  223. data/lib/countries/data/subdivisions/UG.yaml +262 -0
  224. data/lib/countries/data/subdivisions/UM.yaml +4 -0
  225. data/lib/countries/data/subdivisions/US.yaml +118 -0
  226. data/lib/countries/data/subdivisions/UY.yaml +27 -0
  227. data/lib/countries/data/subdivisions/UZ.yaml +65 -0
  228. data/lib/countries/data/subdivisions/VC.yaml +6 -0
  229. data/lib/countries/data/subdivisions/VE.yaml +33 -0
  230. data/lib/countries/data/subdivisions/VN.yaml +131 -0
  231. data/lib/countries/data/subdivisions/VU.yaml +8 -0
  232. data/lib/countries/data/subdivisions/WS.yaml +18 -0
  233. data/lib/countries/data/subdivisions/YE.yaml +16 -0
  234. data/lib/countries/data/subdivisions/ZA.yaml +5 -0
  235. data/lib/countries/data/subdivisions/ZM.yaml +24 -0
  236. data/lib/countries/data/subdivisions/ZW.yaml +21 -0
  237. data/lib/countries/data.rb +19 -50
  238. data/lib/countries/global.rb +0 -1
  239. data/lib/countries/iso3166.rb +3 -0
  240. data/lib/countries/sources/cldr/subdivision.rb +1 -1
  241. data/lib/countries/subdivision.rb +5 -0
  242. data/lib/countries/tasks/postal_codes.rake +5 -1
  243. data/lib/countries/version.rb +1 -1
  244. data/spec/country_spec.rb +118 -22
  245. data/spec/data_spec.rb +12 -8
  246. data/spec/spec_helper.rb +4 -0
  247. data/spec/subdivision_spec.rb +8 -0
  248. metadata +23 -16
  249. data/.rubocop_todo.yml +0 -19
  250. data/lib/countries/tasks/geocoding.rake +0 -106
@@ -40,9 +40,7 @@ module ISO3166
40
40
  end
41
41
 
42
42
  def pluck(*attributes)
43
- all.map do |country|
44
- attributes.map { |attribute| country.data.fetch(attribute.to_s) }
45
- end
43
+ all.map { |country| country.data.fetch_values(*attributes.map(&:to_s)) }
46
44
  end
47
45
 
48
46
  def all_translated(locale = 'en')
@@ -64,6 +62,27 @@ module ISO3166
64
62
  translations.merge(custom_countries)
65
63
  end
66
64
 
65
+ # @param query_val [String] A value to query using `query_method`
66
+ # @param query_method [Symbol] An optional query method, defaults to Country#alpha2
67
+ # @param result_method [Symbol] An optional method of `Country` to apply to the result set.
68
+ # @return [Array] An array of countries matching the provided query, or the result of applying `result_method` to the array of `Country` objects
69
+ def collect_countries_with(query_val, query_method = :alpha2, result_method = :itself)
70
+ return nil unless [query_method, result_method].map { |e| method_defined? e }.all?
71
+
72
+ all.select { |country| country.send(query_method).include? query_val }
73
+ .map { |country| country.send(result_method) }
74
+ end
75
+
76
+ # @param subdivision_str [String] A subdivision name or code to search for. Search includes translated subdivision names.
77
+ # @param result_method [Symbol] An optional method of `Country` to apply to the result set.
78
+ # @return [Array] An array of countries with subdivisions matching the provided name, or the result of applying `result_method` to the array of `Country` objects
79
+ def collect_likely_countries_by_subdivision_name(subdivision_str, result_method = :itself)
80
+ return nil unless method_defined? result_method
81
+
82
+ all.select { |country| country.subdivision_for_string?(subdivision_str) }
83
+ .map { |country| country.send(result_method) }
84
+ end
85
+
67
86
  protected
68
87
 
69
88
  def strip_accents(string)
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ISO3166
4
+ module CountrySubdivisionMethods
5
+ # @param subdivision_str [String] A subdivision name or code to search for. Search includes translated subdivision names.
6
+ # @return [Subdivision] The first subdivision matching the provided string
7
+ def find_subdivision_by_name(subdivision_str)
8
+ subdivisions.select do |k, v|
9
+ subdivision_str == k || v.name == subdivision_str || v.translations.values.include?(subdivision_str)
10
+ end.values.first
11
+ end
12
+
13
+ def subdivision_for_string?(subdivision_str)
14
+ !subdivisions.transform_values(&:translations)
15
+ .select { |k, v| subdivision_str == k || v.values.include?(subdivision_str) }.empty?
16
+ end
17
+
18
+ # +true+ if this Country has any Subdivisions.
19
+ def subdivisions?
20
+ !subdivisions.empty?
21
+ end
22
+
23
+ # @return [Array<ISO3166::Subdivision>] the list of subdivisions for this Country.
24
+ def subdivisions
25
+ @subdivisions ||= if data['subdivisions']
26
+ ISO3166::Data.create_subdivisions(data['subdivisions'])
27
+ else
28
+ ISO3166::Data.subdivisions(alpha2)
29
+ end
30
+ end
31
+
32
+ # @param types [Array<String>] The locale to use for translations.
33
+ # @return [Array<ISO3166::Subdivision>] the list of subdivisions of the given type(s) for this Country.
34
+ def subdivisions_of_types(types)
35
+ subdivisions.select { |_k, v| types.include?(v.type) }
36
+ end
37
+
38
+ # @return [Array<String>] the list of subdivision types for this country
39
+ def subdivision_types
40
+ subdivisions.map { |_k, v| v['type'] }.uniq
41
+ end
42
+
43
+ # @return [Array<String>] the list of humanized subdivision types for this country. Uses ActiveSupport's `#humanize` if available
44
+ def humanized_subdivision_types
45
+ if String.instance_methods.include?(:humanize)
46
+ subdivisions.map { |_k, v| v['type'].humanize }.uniq
47
+ else
48
+ subdivisions.map { |_k, v| humanize_string(v['type']) }.uniq
49
+ end
50
+ end
51
+
52
+ # @param locale [String] The locale to use for translations.
53
+ # @return [Array<Array>] This Country's subdivision pairs of names and codes.
54
+ def subdivision_names_with_codes(locale = 'en')
55
+ subdivisions.map { |k, v| [v.translations[locale] || v.name, k] }
56
+ end
57
+
58
+ # @param locale [String] The locale to use for translations.
59
+ # @return [Array<String>] A list of subdivision names for this country.
60
+ def subdivision_names(locale = 'en')
61
+ subdivisions.map { |_k, v| v.translations[locale] || v.name }
62
+ end
63
+
64
+ def states
65
+ if RUBY_VERSION =~ /^3\.\d\.\d/
66
+ warn 'DEPRECATION WARNING: The Country#states method has been deprecated and will be removed in 6.0. Please use Country#subdivisions instead.',
67
+ uplevel: 1, category: :deprecated
68
+ else
69
+ warn 'DEPRECATION WARNING: The Country#states method has been deprecated and will be removed in 6.0. Please use Country#subdivisions instead.',
70
+ uplevel: 1
71
+ end
72
+
73
+ subdivisions
74
+ end
75
+
76
+ private
77
+
78
+ def humanize_string(str)
79
+ str[0].upcase + str.tr('_', ' ')[1..]
80
+ end
81
+ end
82
+ end
@@ -6,7 +6,6 @@ module ISO3166
6
6
  # Optional extension which allows you to get back a +Money::Currency+ object with all the currency info.
7
7
  # This requires enabling the integration with the {Money}[https://github.com/RubyMoney/money] gem (See {ISO3166::Configuration#enable_currency_extension!})
8
8
  module CountryCurrencyMethods
9
-
10
9
  # @return [Money::Currency] The currency data for this Country's +currency_code+
11
10
  def currency
12
11
  Money::Currency.find(data['currency_code'])
@@ -57,9 +57,7 @@ module ISO3166
57
57
  raise "Invalid attribute name '#{attribute}'" unless searchable_attribute?(attribute.to_sym)
58
58
 
59
59
  attributes = Array(attribute.to_s)
60
- if attribute.to_s == 'any_name'
61
- attributes = %w[iso_long_name iso_short_name unofficial_names translated_names]
62
- end
60
+ attributes = %w[iso_long_name iso_short_name unofficial_names translated_names] if attribute.to_s == 'any_name'
63
61
 
64
62
  [attributes, parse_value(val)]
65
63
  end
@@ -75,7 +73,7 @@ module ISO3166
75
73
 
76
74
  def searchable_attributes
77
75
  # Add name and names until we complete the deprecation of the finders
78
- instance_methods - UNSEARCHABLE_METHODS + [:name, :names, :any_name]
76
+ instance_methods - UNSEARCHABLE_METHODS + %i[name names any_name]
79
77
  end
80
78
  end
81
79
  end
@@ -5,6 +5,7 @@ module ISO3166
5
5
  extend CountryClassMethods
6
6
  extend CountryFinderMethods
7
7
  include Emoji
8
+ include CountrySubdivisionMethods
8
9
  attr_reader :data
9
10
 
10
11
  ISO3166::DEFAULT_COUNTRY_HASH.each do |method_name, _type|
@@ -50,65 +51,24 @@ module ISO3166
50
51
  to_s <=> other.to_s
51
52
  end
52
53
 
53
- # +true+ if this Country has any Subdivisions.
54
- def subdivisions?
55
- !subdivisions.empty?
56
- end
57
-
58
- # @return [Array<ISO3166::Subdivision>] the list of subdivisions for this Country.
59
- def subdivisions
60
- @subdivisions ||= if data['subdivisions']
61
- ISO3166::Data.create_subdivisions(data['subdivisions'])
62
- else
63
- ISO3166::Data.subdivisions(alpha2)
64
- end
65
- end
66
-
67
- # @param types [Array<String>] The locale to use for translations.
68
- # @return [Array<ISO3166::Subdivision>] the list of subdivisions of the given type(s) for this Country.
69
- def subdivisions_of_types(types)
70
- subdivisions.select{|k,v| types.include?(v.type)}
71
- end
72
-
73
- # @return [Array<String>] the list of subdivision types for this country
74
- def subdivision_types
75
- subdivisions.map{|k,v| v['type']}.uniq
76
- end
77
-
78
- # @return [Array<String>] the list of humanized subdivision types for this country. Uses ActiveSupport's `#humanize` if available
79
- def humanized_subdivision_types
80
- if String.instance_methods.include?(:humanize)
81
- subdivisions.map{|k,v| v['type'].humanize}.uniq
82
- else
83
- subdivisions.map{|k,v| v['type'][0].upcase + v['type'].tr('_', ' ')[1..-1]}.uniq
84
- end
85
- end
86
-
87
- # @param locale [String] The locale to use for translations.
88
- # @return [Array<Array>] This Country's subdivision pairs of names and codes.
89
- def subdivision_names_with_codes(locale = 'en')
90
- subdivisions.map { |k, v| [v.translations[locale] || v.name, k] }
54
+ # +true+ if this country is a member of the European Union.
55
+ def in_eu?
56
+ data['eu_member'].nil? ? false : data['eu_member']
91
57
  end
92
58
 
93
- # @param locale [String] The locale to use for translations.
94
- # @return [Array<String>] A list of subdivision names for this country.
95
- def subdivision_names(locale = 'en')
96
- subdivisions.map { |k, v| v.translations[locale] || v.name }
59
+ # +true+ if this country is a member of the G7.
60
+ def in_g7?
61
+ data['g7_member'].nil? ? false : data['g7_member']
97
62
  end
98
63
 
99
- def states
100
- if RUBY_VERSION =~ /^3\.\d\.\d/
101
- warn "DEPRECATION WARNING: The Country#states method has been deprecated and will be removed in 6.0. Please use Country#subdivisions instead.", uplevel: 1, category: :deprecated
102
- else
103
- warn "DEPRECATION WARNING: The Country#states method has been deprecated and will be removed in 6.0. Please use Country#subdivisions instead.", uplevel: 1
104
- end
105
-
106
- subdivisions
64
+ # +true+ if this country is a member of the G20.
65
+ def in_g20?
66
+ data['g20_member'].nil? ? false : data['g20_member']
107
67
  end
108
68
 
109
- # +true+ if this country is a member of the European Union.
110
- def in_eu?
111
- data['eu_member'].nil? ? false : data['eu_member']
69
+ # +true+ if this country is a member of the European Economic Area or it is UK
70
+ def gdpr_compliant?
71
+ data['eea_member'] || alpha2 == 'GB'
112
72
  end
113
73
 
114
74
  # +true+ if this country is a member of the European Economic Area.
@@ -11,6 +11,7 @@ AR:
11
11
  continent: South America
12
12
  country_code: '54'
13
13
  currency_code: ARS
14
+ g20_member: true
14
15
  gec: AR
15
16
  geo:
16
17
  latitude: -38.416097
@@ -10,6 +10,7 @@ AU:
10
10
  continent: Australia
11
11
  country_code: '61'
12
12
  currency_code: AUD
13
+ g20_member: true
13
14
  gec: AS
14
15
  geo:
15
16
  latitude: -25.274398
@@ -10,6 +10,7 @@ BR:
10
10
  continent: South America
11
11
  country_code: '55'
12
12
  currency_code: BRL
13
+ g20_member: true
13
14
  gec: BR
14
15
  geo:
15
16
  latitude: -14.235004
@@ -10,6 +10,8 @@ CA:
10
10
  continent: North America
11
11
  country_code: '1'
12
12
  currency_code: CAD
13
+ g7_member: true
14
+ g20_member: true
13
15
  gec: CA
14
16
  geo:
15
17
  latitude: 56.130366
@@ -10,6 +10,7 @@ CN:
10
10
  continent: Asia
11
11
  country_code: '86'
12
12
  currency_code: CNY
13
+ g20_member: true
13
14
  gec: CH
14
15
  geo:
15
16
  latitude: 35.86166
@@ -12,6 +12,8 @@ DE:
12
12
  currency_code: EUR
13
13
  eea_member: true
14
14
  eu_member: true
15
+ g7_member: true
16
+ g20_member: true
15
17
  gec: GM
16
18
  geo:
17
19
  latitude: 51.165691
@@ -12,6 +12,8 @@ FR:
12
12
  currency_code: EUR
13
13
  eea_member: true
14
14
  eu_member: true
15
+ g7_member: true
16
+ g20_member: true
15
17
  gec: FR
16
18
  geo:
17
19
  latitude: 46.227638
@@ -14,6 +14,8 @@ GB:
14
14
  currency_code: GBP
15
15
  eea_member: false
16
16
  eu_member: false
17
+ g7_member: true
18
+ g20_member: true
17
19
  gec: UK
18
20
  geo:
19
21
  latitude: 55.378051
@@ -11,6 +11,7 @@ ID:
11
11
  continent: Asia
12
12
  country_code: '62'
13
13
  currency_code: IDR
14
+ g20_member: true
14
15
  gec: ID
15
16
  geo:
16
17
  latitude: -0.789275
@@ -11,6 +11,7 @@ IN:
11
11
  continent: Asia
12
12
  country_code: '91'
13
13
  currency_code: INR
14
+ g20_member: true
14
15
  gec: IN
15
16
  geo:
16
17
  latitude: 20.593684
@@ -12,6 +12,8 @@ IT:
12
12
  currency_code: EUR
13
13
  eea_member: true
14
14
  eu_member: true
15
+ g7_member: true
16
+ g20_member: true
15
17
  gec: IT
16
18
  geo:
17
19
  latitude: 41.87194
@@ -10,6 +10,8 @@ JP:
10
10
  continent: Asia
11
11
  country_code: '81'
12
12
  currency_code: JPY
13
+ g7_member: true
14
+ g20_member: true
13
15
  gec: JA
14
16
  geo:
15
17
  latitude: 36.204824
@@ -11,6 +11,7 @@ KR:
11
11
  continent: Asia
12
12
  country_code: '82'
13
13
  currency_code: KRW
14
+ g20_member: true
14
15
  gec: KS
15
16
  geo:
16
17
  latitude: 35.907757
@@ -10,6 +10,7 @@ MX:
10
10
  continent: North America
11
11
  country_code: '52'
12
12
  currency_code: MXN
13
+ g20_member: true
13
14
  gec: MX
14
15
  geo:
15
16
  latitude: 23.634501
@@ -10,6 +10,7 @@ RU:
10
10
  continent: Europe
11
11
  country_code: '7'
12
12
  currency_code: RUB
13
+ g20_member: true
13
14
  gec: RS
14
15
  geo:
15
16
  latitude: 61.52401
@@ -10,6 +10,7 @@ SA:
10
10
  continent: Asia
11
11
  country_code: '966'
12
12
  currency_code: SAR
13
+ g20_member: true
13
14
  gec: SA
14
15
  geo:
15
16
  latitude: 23.885942
@@ -10,6 +10,7 @@ TR:
10
10
  continent: Europe
11
11
  country_code: '90'
12
12
  currency_code: TRY
13
+ g20_member: true
13
14
  gec: TU
14
15
  geo:
15
16
  latitude: 38.963745
@@ -10,6 +10,8 @@ US:
10
10
  continent: North America
11
11
  country_code: '1'
12
12
  currency_code: USD
13
+ g7_member: true
14
+ g20_member: true
13
15
  gec: US
14
16
  geo:
15
17
  latitude: 37.09024
@@ -12,6 +12,7 @@ ZA:
12
12
  continent: Africa
13
13
  country_code: '27'
14
14
  currency_code: ZAR
15
+ g20_member: true
15
16
  gec: SF
16
17
  geo:
17
18
  latitude: -30.559482
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ISO3166
4
+ module LocalesMethods
5
+ private
6
+
7
+ def locales_to_load
8
+ requested_locales - loaded_locales
9
+ end
10
+
11
+ def locales_to_remove
12
+ loaded_locales - requested_locales
13
+ end
14
+
15
+ def requested_locales
16
+ ISO3166.configuration.locales.map { |locale| locale.to_s.downcase }
17
+ end
18
+
19
+ def loaded_locales
20
+ ISO3166.configuration.loaded_locales.map { |locale| locale.to_s.downcase }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ISO3166
4
+ module SubdivisionMethods
5
+ def subdivision_data(alpha2)
6
+ data = load_data_for_alpha2(alpha2)
7
+ locales = ISO3166.configuration.locales.map(&:to_s)
8
+
9
+ data.each_value { |subdivision| subdivision['translations'] = subdivision['translations'].slice(*locales) }
10
+
11
+ data
12
+ end
13
+
14
+ def load_data_for_alpha2(alpha2)
15
+ file = subdivision_file_path(alpha2)
16
+ File.exist?(file) ? YAML.load_file(file) : {}
17
+ end
18
+
19
+ def subdivisions(alpha2)
20
+ @subdivisions ||= {}
21
+ @subdivisions[alpha2] ||= create_subdivisions(subdivision_data(alpha2))
22
+ end
23
+
24
+ def create_subdivisions(subdivision_data)
25
+ subdivision_data.transform_values do |subdivision|
26
+ Subdivision.new(subdivision)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -12,6 +12,7 @@
12
12
  max_longitude: 1.6037142
13
13
  translations:
14
14
  en: Canillo
15
+ ja: カニーリョ教区
15
16
  comments:
16
17
  type: parish
17
18
  '03':
@@ -27,6 +28,7 @@
27
28
  max_longitude: 1.5901645
28
29
  translations:
29
30
  en: Encamp
31
+ ja: アンカム教区
30
32
  comments:
31
33
  type: parish
32
34
  '04':
@@ -42,6 +44,7 @@
42
44
  max_longitude: 1.5204314
43
45
  translations:
44
46
  en: La Massana
47
+ ja: ラ・マサナ教区
45
48
  comments:
46
49
  type: parish
47
50
  '05':
@@ -57,6 +60,7 @@
57
60
  max_longitude: 1.5374774
58
61
  translations:
59
62
  en: Ordino
63
+ ja: オルディノ教区
60
64
  comments:
61
65
  type: parish
62
66
  '06':
@@ -73,6 +77,7 @@
73
77
  max_longitude: 1.4963642
74
78
  translations:
75
79
  en: Sant Julià de Lòria
80
+ ja: サン・ジュリア・デ・ロリア教区
76
81
  comments:
77
82
  type: parish
78
83
  '07':
@@ -90,6 +95,7 @@
90
95
  max_longitude: 1.5353385
91
96
  translations:
92
97
  en: Andorra la Vella
98
+ ja: アンドラ・ラ・ベリャ教区
93
99
  comments:
94
100
  type: parish
95
101
  '08':
@@ -106,5 +112,6 @@
106
112
  max_longitude: 1.5532685
107
113
  translations:
108
114
  en: Escaldes-Engordany
115
+ ja: エスカルデス=エンゴルダニ教区
109
116
  comments:
110
117
  type: parish
@@ -74,6 +74,7 @@ AJ:
74
74
  yo: Ajman
75
75
  'no': Emiratet Ajman
76
76
  yo_BJ: Ajman
77
+ bs: Ajman (emirat)
77
78
  comments:
78
79
  type: emirate
79
80
  AZ:
@@ -159,6 +160,9 @@ AZ:
159
160
  yue: 阿布扎比酋長國
160
161
  mk: Абу Даби
161
162
  'no': Emiratet Abu Dhabi
163
+ bs: Abu Dhabi (emirat)
164
+ ha: Abu Dhabi (Masarauta)
165
+ ha_NE: Abu Dhabi (Masarauta)
162
166
  comments:
163
167
  type: emirate
164
168
  DU:
@@ -235,6 +239,10 @@ DU:
235
239
  uz: Dubay
236
240
  bs: Dubai
237
241
  'no': Emiratet Dubai
242
+ ga: Dubai
243
+ ha: Dubai
244
+ ha_NE: Dubai
245
+ ms: Amiriah Dubai
238
246
  comments:
239
247
  type: emirate
240
248
  FU:
@@ -314,6 +322,9 @@ FU:
314
322
  yo: Fujairah
315
323
  'no': Emiratet Fujairah
316
324
  yo_BJ: Fujairah
325
+ bs: Fujairah (emirat)
326
+ is: Fúdsaíra
327
+ ka: ალ-ფუჯაირას საამირო
317
328
  comments:
318
329
  type: emirate
319
330
  RK:
@@ -354,6 +365,7 @@ RK:
354
365
  hy: Ռաս-ալ-Խայմայի էմիրություն
355
366
  id: Ras al-Khaimah
356
367
  it: Ras al-Khaima
368
+ ja: ラアス・アル=ハイマ
357
369
  kn: ರಾಸ್ ಅಲ್ ಖೈಮಾ
358
370
  ko: 라스알카이마 토후국
359
371
  lt: Ras al Chaima
@@ -392,6 +404,9 @@ RK:
392
404
  mk: Рас ел-Хајма
393
405
  'no': Emiratet Ras al-Khaimah
394
406
  yo_BJ: Ras al Khaimah
407
+ bs: Ras al-Khaimah (emirat)
408
+ gl: Ras al-Jaimah
409
+ is: Ras al-Kaíma
395
410
  comments:
396
411
  type: emirate
397
412
  SH:
@@ -471,6 +486,7 @@ SH:
471
486
  yo: Sharjah
472
487
  'no': Emiratet Sharjah
473
488
  yo_BJ: Sharjah
489
+ bs: Sharjah (emirat)
474
490
  comments:
475
491
  type: emirate
476
492
  UQ:
@@ -511,6 +527,7 @@ UQ:
511
527
  hy: Ումմ ալ-Քուվեյնի Էմիրություն
512
528
  id: Umm al-Qaiwain
513
529
  it: Umm al-Qaywayn
530
+ ja: ウンム・アル=カイワイン
514
531
  ka: უმ-ელ-კაივაინის საამირო
515
532
  kn: ಉಮ್ ಅಲ್ ಕ್ವೈನ್
516
533
  ko: 움알쿠와인 토후국
@@ -548,5 +565,6 @@ UQ:
548
565
  yo: Um Al Quwain
549
566
  'no': Emiratet Umm al-Qaiwain
550
567
  yo_BJ: Um Al Quwain
568
+ bs: Umm al-Quwain (emirat)
551
569
  comments:
552
570
  type: emirate