countries 5.4.0 → 5.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +61 -0
- data/.github/workflows/tests.yml +4 -0
- data/.gitignore +0 -1
- data/.rubocop.yml +17 -8
- data/CHANGELOG.md +8 -0
- data/Gemfile +1 -2
- data/Gemfile.lock +84 -0
- data/README.md +41 -1
- data/Rakefile +2 -3
- data/countries.gemspec +1 -1
- data/lib/countries/cache/countries.json +1 -1
- data/lib/countries/country/class_methods.rb +22 -3
- data/lib/countries/country/country_subdivision_methods.rb +82 -0
- data/lib/countries/country/currency_methods.rb +0 -1
- data/lib/countries/country/finder_methods.rb +2 -4
- data/lib/countries/country.rb +13 -53
- data/lib/countries/data/countries/AR.yaml +1 -0
- data/lib/countries/data/countries/AU.yaml +1 -0
- data/lib/countries/data/countries/BR.yaml +1 -0
- data/lib/countries/data/countries/CA.yaml +2 -0
- data/lib/countries/data/countries/CN.yaml +1 -0
- data/lib/countries/data/countries/DE.yaml +2 -0
- data/lib/countries/data/countries/FR.yaml +2 -0
- data/lib/countries/data/countries/GB.yaml +2 -0
- data/lib/countries/data/countries/ID.yaml +1 -0
- data/lib/countries/data/countries/IN.yaml +1 -0
- data/lib/countries/data/countries/IT.yaml +2 -0
- data/lib/countries/data/countries/JP.yaml +2 -0
- data/lib/countries/data/countries/KR.yaml +1 -0
- data/lib/countries/data/countries/MX.yaml +1 -0
- data/lib/countries/data/countries/RU.yaml +1 -0
- data/lib/countries/data/countries/SA.yaml +1 -0
- data/lib/countries/data/countries/TR.yaml +1 -0
- data/lib/countries/data/countries/US.yaml +2 -0
- data/lib/countries/data/countries/ZA.yaml +1 -0
- data/lib/countries/data/locales_methods.rb +23 -0
- data/lib/countries/data/subdivision_methods.rb +30 -0
- data/lib/countries/data/subdivisions/AD.yaml +7 -0
- data/lib/countries/data/subdivisions/AE.yaml +18 -0
- data/lib/countries/data/subdivisions/AF.yaml +167 -2
- data/lib/countries/data/subdivisions/AG.yaml +9 -0
- data/lib/countries/data/subdivisions/AL.yaml +57 -0
- data/lib/countries/data/subdivisions/AM.yaml +34 -0
- data/lib/countries/data/subdivisions/AO.yaml +36 -0
- data/lib/countries/data/subdivisions/AR.yaml +46 -0
- data/lib/countries/data/subdivisions/AT.yaml +28 -0
- data/lib/countries/data/subdivisions/AU.yaml +29 -0
- data/lib/countries/data/subdivisions/AZ.yaml +239 -0
- data/lib/countries/data/subdivisions/BA.yaml +5 -0
- data/lib/countries/data/subdivisions/BB.yaml +4 -0
- data/lib/countries/data/subdivisions/BD.yaml +139 -0
- data/lib/countries/data/subdivisions/BE.yaml +34 -0
- data/lib/countries/data/subdivisions/BF.yaml +56 -0
- data/lib/countries/data/subdivisions/BG.yaml +30 -0
- data/lib/countries/data/subdivisions/BH.yaml +13 -0
- data/lib/countries/data/subdivisions/BI.yaml +54 -0
- data/lib/countries/data/subdivisions/BJ.yaml +22 -0
- data/lib/countries/data/subdivisions/BN.yaml +9 -0
- data/lib/countries/data/subdivisions/BO.yaml +35 -0
- data/lib/countries/data/subdivisions/BQ.yaml +4 -0
- data/lib/countries/data/subdivisions/BR.yaml +14 -0
- data/lib/countries/data/subdivisions/BS.yaml +24 -0
- data/lib/countries/data/subdivisions/BT.yaml +24 -0
- data/lib/countries/data/subdivisions/BW.yaml +24 -0
- data/lib/countries/data/subdivisions/BY.yaml +5 -0
- data/lib/countries/data/subdivisions/BZ.yaml +3 -0
- data/lib/countries/data/subdivisions/CA.yaml +24 -0
- data/lib/countries/data/subdivisions/CD.yaml +77 -0
- data/lib/countries/data/subdivisions/CF.yaml +15 -0
- data/lib/countries/data/subdivisions/CG.yaml +18 -0
- data/lib/countries/data/subdivisions/CH.yaml +92 -0
- data/lib/countries/data/subdivisions/CI.yaml +65 -0
- data/lib/countries/data/subdivisions/CL.yaml +45 -2
- data/lib/countries/data/subdivisions/CM.yaml +22 -0
- data/lib/countries/data/subdivisions/CN.yaml +98 -0
- data/lib/countries/data/subdivisions/CO.yaml +68 -0
- data/lib/countries/data/subdivisions/CR.yaml +14 -0
- data/lib/countries/data/subdivisions/CU.yaml +42 -0
- data/lib/countries/data/subdivisions/CV.yaml +32 -0
- data/lib/countries/data/subdivisions/CY.yaml +18 -0
- data/lib/countries/data/subdivisions/CZ.yaml +227 -0
- data/lib/countries/data/subdivisions/DE.yaml +31 -0
- data/lib/countries/data/subdivisions/DJ.yaml +16 -0
- data/lib/countries/data/subdivisions/DK.yaml +13 -0
- data/lib/countries/data/subdivisions/DM.yaml +1 -0
- data/lib/countries/data/subdivisions/DO.yaml +102 -0
- data/lib/countries/data/subdivisions/DZ.yaml +104 -0
- data/lib/countries/data/subdivisions/EC.yaml +72 -0
- data/lib/countries/data/subdivisions/EE.yaml +6 -0
- data/lib/countries/data/subdivisions/EG.yaml +54 -0
- data/lib/countries/data/subdivisions/ER.yaml +2 -0
- data/lib/countries/data/subdivisions/ES.yaml +252 -0
- data/lib/countries/data/subdivisions/ET.yaml +27 -0
- data/lib/countries/data/subdivisions/FI.yaml +78 -0
- data/lib/countries/data/subdivisions/FJ.yaml +30 -0
- data/lib/countries/data/subdivisions/FM.yaml +11 -0
- data/lib/countries/data/subdivisions/FR.yaml +332 -1
- data/lib/countries/data/subdivisions/GA.yaml +24 -0
- data/lib/countries/data/subdivisions/GB.yaml +488 -0
- data/lib/countries/data/subdivisions/GD.yaml +10 -0
- data/lib/countries/data/subdivisions/GE.yaml +34 -0
- data/lib/countries/data/subdivisions/GH.yaml +79 -0
- data/lib/countries/data/subdivisions/GL.yaml +58 -0
- data/lib/countries/data/subdivisions/GM.yaml +10 -0
- data/lib/countries/data/subdivisions/GN.yaml +65 -0
- data/lib/countries/data/subdivisions/GQ.yaml +36 -0
- data/lib/countries/data/subdivisions/GR.yaml +41 -0
- data/lib/countries/data/subdivisions/GW.yaml +24 -0
- data/lib/countries/data/subdivisions/GY.yaml +31 -0
- data/lib/countries/data/subdivisions/HN.yaml +21 -0
- data/lib/countries/data/subdivisions/HR.yaml +82 -0
- data/lib/countries/data/subdivisions/HT.yaml +14 -0
- data/lib/countries/data/subdivisions/HU.yaml +94 -0
- data/lib/countries/data/subdivisions/ID.yaml +99 -0
- data/lib/countries/data/subdivisions/IE.yaml +39 -0
- data/lib/countries/data/subdivisions/IL.yaml +15 -0
- data/lib/countries/data/subdivisions/IN.yaml +210 -0
- data/lib/countries/data/subdivisions/IQ.yaml +59 -0
- data/lib/countries/data/subdivisions/IR.yaml +2 -0
- data/lib/countries/data/subdivisions/IS.yaml +560 -0
- data/lib/countries/data/subdivisions/IT.yaml +321 -0
- data/lib/countries/data/subdivisions/JM.yaml +22 -0
- data/lib/countries/data/subdivisions/JO.yaml +16 -0
- data/lib/countries/data/subdivisions/JP.yaml +42 -0
- data/lib/countries/data/subdivisions/KE.yaml +298 -0
- data/lib/countries/data/subdivisions/KG.yaml +28 -0
- data/lib/countries/data/subdivisions/KH.yaml +108 -0
- data/lib/countries/data/subdivisions/KI.yaml +6 -0
- data/lib/countries/data/subdivisions/KM.yaml +4 -0
- data/lib/countries/data/subdivisions/KN.yaml +6 -0
- data/lib/countries/data/subdivisions/KP.yaml +42 -0
- data/lib/countries/data/subdivisions/KR.yaml +36 -0
- data/lib/countries/data/subdivisions/KW.yaml +5 -0
- data/lib/countries/data/subdivisions/KZ.yaml +113 -0
- data/lib/countries/data/subdivisions/LA.yaml +49 -0
- data/lib/countries/data/subdivisions/LB.yaml +28 -0
- data/lib/countries/data/subdivisions/LC.yaml +6 -0
- data/lib/countries/data/subdivisions/LI.yaml +37 -0
- data/lib/countries/data/subdivisions/LK.yaml +67 -0
- data/lib/countries/data/subdivisions/LR.yaml +16 -0
- data/lib/countries/data/subdivisions/LS.yaml +23 -0
- data/lib/countries/data/subdivisions/LT.yaml +315 -0
- data/lib/countries/data/subdivisions/LU.yaml +31 -0
- data/lib/countries/data/subdivisions/LV.yaml +83 -0
- data/lib/countries/data/subdivisions/LY.yaml +16 -0
- data/lib/countries/data/subdivisions/MA.yaml +827 -12
- data/lib/countries/data/subdivisions/MC.yaml +47 -0
- data/lib/countries/data/subdivisions/MD.yaml +41 -0
- data/lib/countries/data/subdivisions/ME.yaml +83 -0
- data/lib/countries/data/subdivisions/MG.yaml +21 -0
- data/lib/countries/data/subdivisions/MH.yaml +70 -0
- data/lib/countries/data/subdivisions/MK.yaml +505 -0
- data/lib/countries/data/subdivisions/ML.yaml +33 -0
- data/lib/countries/data/subdivisions/MM.yaml +51 -0
- data/lib/countries/data/subdivisions/MN.yaml +94 -0
- data/lib/countries/data/subdivisions/MR.yaml +32 -0
- data/lib/countries/data/subdivisions/MT.yaml +126 -0
- data/lib/countries/data/subdivisions/MU.yaml +21 -0
- data/lib/countries/data/subdivisions/MV.yaml +20 -0
- data/lib/countries/data/subdivisions/MW.yaml +52 -0
- data/lib/countries/data/subdivisions/MX.yaml +23 -0
- data/lib/countries/data/subdivisions/MY.yaml +24 -0
- data/lib/countries/data/subdivisions/MZ.yaml +20 -0
- data/lib/countries/data/subdivisions/NA.yaml +28 -0
- data/lib/countries/data/subdivisions/NE.yaml +9 -0
- data/lib/countries/data/subdivisions/NG.yaml +89 -0
- data/lib/countries/data/subdivisions/NI.yaml +25 -0
- data/lib/countries/data/subdivisions/NL.yaml +24 -0
- data/lib/countries/data/subdivisions/NO.yaml +138 -1
- data/lib/countries/data/subdivisions/NP.yaml +9 -0
- data/lib/countries/data/subdivisions/NR.yaml +19 -0
- data/lib/countries/data/subdivisions/NZ.yaml +34 -0
- data/lib/countries/data/subdivisions/OM.yaml +10 -0
- data/lib/countries/data/subdivisions/PA.yaml +27 -0
- data/lib/countries/data/subdivisions/PE.yaml +24 -0
- data/lib/countries/data/subdivisions/PG.yaml +46 -0
- data/lib/countries/data/subdivisions/PH.yaml +293 -0
- data/lib/countries/data/subdivisions/PK.yaml +22 -0
- data/lib/countries/data/subdivisions/PL.yaml +141 -0
- data/lib/countries/data/subdivisions/PS.yaml +41 -0
- data/lib/countries/data/subdivisions/PT.yaml +36 -0
- data/lib/countries/data/subdivisions/PW.yaml +24 -0
- data/lib/countries/data/subdivisions/PY.yaml +21 -0
- data/lib/countries/data/subdivisions/QA.yaml +26 -0
- data/lib/countries/data/subdivisions/RO.yaml +189 -0
- data/lib/countries/data/subdivisions/RS.yaml +112 -0
- data/lib/countries/data/subdivisions/RU.yaml +123 -0
- data/lib/countries/data/subdivisions/RW.yaml +7 -0
- data/lib/countries/data/subdivisions/SA.yaml +38 -0
- data/lib/countries/data/subdivisions/SB.yaml +11 -0
- data/lib/countries/data/subdivisions/SC.yaml +45 -0
- data/lib/countries/data/subdivisions/SD.yaml +15 -0
- data/lib/countries/data/subdivisions/SE.yaml +42 -0
- data/lib/countries/data/subdivisions/SG.yaml +8 -0
- data/lib/countries/data/subdivisions/SH.yaml +6 -0
- data/lib/countries/data/subdivisions/SI.yaml +735 -0
- data/lib/countries/data/subdivisions/SK.yaml +22 -0
- data/lib/countries/data/subdivisions/SL.yaml +7 -0
- data/lib/countries/data/subdivisions/SM.yaml +19 -0
- data/lib/countries/data/subdivisions/SN.yaml +43 -0
- data/lib/countries/data/subdivisions/SO.yaml +71 -0
- data/lib/countries/data/subdivisions/SR.yaml +17 -0
- data/lib/countries/data/subdivisions/SS.yaml +4 -0
- data/lib/countries/data/subdivisions/ST.yaml +127 -0
- data/lib/countries/data/subdivisions/SV.yaml +20 -0
- data/lib/countries/data/subdivisions/SY.yaml +53 -0
- data/lib/countries/data/subdivisions/SZ.yaml +18 -0
- data/lib/countries/data/subdivisions/TD.yaml +51 -0
- data/lib/countries/data/subdivisions/TG.yaml +13 -0
- data/lib/countries/data/subdivisions/TH.yaml +231 -0
- data/lib/countries/data/subdivisions/TJ.yaml +15 -0
- data/lib/countries/data/subdivisions/TL.yaml +38 -0
- data/lib/countries/data/subdivisions/TM.yaml +15 -0
- data/lib/countries/data/subdivisions/TN.yaml +25 -0
- data/lib/countries/data/subdivisions/TO.yaml +1 -0
- data/lib/countries/data/subdivisions/TR.yaml +93 -0
- data/lib/countries/data/subdivisions/TT.yaml +25 -0
- data/lib/countries/data/subdivisions/TV.yaml +25 -0
- data/lib/countries/data/subdivisions/TW.yaml +106 -0
- data/lib/countries/data/subdivisions/TZ.yaml +38 -0
- data/lib/countries/data/subdivisions/UA.yaml +86 -4
- data/lib/countries/data/subdivisions/UG.yaml +262 -0
- data/lib/countries/data/subdivisions/UM.yaml +4 -0
- data/lib/countries/data/subdivisions/US.yaml +118 -0
- data/lib/countries/data/subdivisions/UY.yaml +27 -0
- data/lib/countries/data/subdivisions/UZ.yaml +65 -0
- data/lib/countries/data/subdivisions/VC.yaml +6 -0
- data/lib/countries/data/subdivisions/VE.yaml +33 -0
- data/lib/countries/data/subdivisions/VN.yaml +131 -0
- data/lib/countries/data/subdivisions/VU.yaml +8 -0
- data/lib/countries/data/subdivisions/WS.yaml +18 -0
- data/lib/countries/data/subdivisions/YE.yaml +16 -0
- data/lib/countries/data/subdivisions/ZA.yaml +5 -0
- data/lib/countries/data/subdivisions/ZM.yaml +24 -0
- data/lib/countries/data/subdivisions/ZW.yaml +21 -0
- data/lib/countries/data.rb +19 -50
- data/lib/countries/global.rb +0 -1
- data/lib/countries/iso3166.rb +3 -0
- data/lib/countries/sources/cldr/subdivision.rb +1 -1
- data/lib/countries/subdivision.rb +5 -0
- data/lib/countries/tasks/postal_codes.rake +5 -1
- data/lib/countries/version.rb +1 -1
- data/spec/country_spec.rb +118 -22
- data/spec/data_spec.rb +12 -8
- data/spec/spec_helper.rb +4 -0
- data/spec/subdivision_spec.rb +8 -0
- metadata +23 -16
- data/.rubocop_todo.yml +0 -19
- 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
|
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 + [
|
76
|
+
instance_methods - UNSEARCHABLE_METHODS + %i[name names any_name]
|
79
77
|
end
|
80
78
|
end
|
81
79
|
end
|
data/lib/countries/country.rb
CHANGED
@@ -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
|
-
#
|
54
|
-
def
|
55
|
-
|
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
|
-
#
|
94
|
-
|
95
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
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
|
110
|
-
def
|
111
|
-
data['
|
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.
|
@@ -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
|