countries 6.0.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/lib/countries/cache/countries.json +1 -1
  3. data/lib/countries/configuration.rb +6 -2
  4. data/lib/countries/country/class_methods.rb +1 -1
  5. data/lib/countries/country/conversion_methods.rb +17 -0
  6. data/lib/countries/country/country_subdivision_methods.rb +2 -14
  7. data/lib/countries/country/finder_methods.rb +2 -3
  8. data/lib/countries/country.rb +3 -2
  9. data/lib/countries/data/countries/AM.yaml +0 -1
  10. data/lib/countries/data/countries/AR.yaml +1 -0
  11. data/lib/countries/data/countries/BG.yaml +1 -0
  12. data/lib/countries/data/countries/CD.yaml +1 -0
  13. data/lib/countries/data/countries/CG.yaml +1 -0
  14. data/lib/countries/data/countries/CH.yaml +5 -3
  15. data/lib/countries/data/countries/EE.yaml +1 -1
  16. data/lib/countries/data/countries/ER.yaml +1 -1
  17. data/lib/countries/data/countries/ES.yaml +8 -0
  18. data/lib/countries/data/countries/FI.yaml +1 -1
  19. data/lib/countries/data/countries/FJ.yaml +0 -1
  20. data/lib/countries/data/countries/GB.yaml +1 -0
  21. data/lib/countries/data/countries/MM.yaml +1 -0
  22. data/lib/countries/data/countries/NL.yaml +1 -0
  23. data/lib/countries/data/countries/PY.yaml +1 -1
  24. data/lib/countries/data/countries/UZ.yaml +0 -1
  25. data/lib/countries/data/subdivisions/GB.yaml +1 -1
  26. data/lib/countries/data/subdivisions/GT.yaml +44 -44
  27. data/lib/countries/data.rb +2 -2
  28. data/lib/countries/iso3166.rb +1 -0
  29. data/lib/countries/sources/cldr/subdivision_updater.rb +1 -1
  30. data/lib/countries/sources.rb +5 -5
  31. data/lib/countries/translations.rb +1 -1
  32. data/lib/countries/version.rb +1 -1
  33. metadata +5 -4
@@ -19,13 +19,17 @@ module ISO3166
19
19
  end
20
20
 
21
21
  class Configuration
22
- attr_accessor :locales, :loaded_locales
22
+ attr_accessor :loaded_locales
23
+ attr_writer :locales
23
24
 
24
25
  def initialize
25
- @locales = default_locales
26
26
  @loaded_locales = []
27
27
  end
28
28
 
29
+ def locales
30
+ @locales ||= default_locales
31
+ end
32
+
29
33
  # Enables the integration with the {Money}[https://github.com/RubyMoney/money] gem
30
34
  #
31
35
  # Please note that it requires you to add "money" gem to your gemfile.
@@ -34,7 +34,7 @@ module ISO3166
34
34
 
35
35
  def all_names_with_codes(locale = 'en')
36
36
  Country.all.map do |c|
37
- lc = (c.translation(locale) || c.iso_short_name)
37
+ lc = c.translation(locale) || c.iso_short_name
38
38
  [lc.respond_to?('html_safe') ? lc.html_safe : lc, c.alpha2]
39
39
  end.sort
40
40
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ISO3166
4
+ module ConversionMethods
5
+ # @param alpha2 [String] ISO 3166 alpha-2 country code.
6
+ # @return [String] ISO 3166 alpha-3 country code.
7
+ def from_alpha2_to_alpha3(alpha2)
8
+ find_country_by_alpha2(alpha2)&.alpha3
9
+ end
10
+
11
+ # @param alpha3 [String] ISO 3166 alpha-3 country code.
12
+ # @return [String] ISO 3166 alpha-2 country code.
13
+ def from_alpha3_to_alpha2(alpha3)
14
+ find_country_by_alpha3(alpha3)&.alpha2
15
+ end
16
+ end
17
+ end
@@ -11,8 +11,8 @@ module ISO3166
11
11
  end
12
12
 
13
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?
14
+ subdivisions.transform_values(&:translations)
15
+ .any? { |k, v| subdivision_str == k || v.values.include?(subdivision_str) }
16
16
  end
17
17
 
18
18
  # +true+ if this Country has any Subdivisions.
@@ -61,18 +61,6 @@ module ISO3166
61
61
  subdivisions.map { |_k, v| v.translations[locale] || v.name }
62
62
  end
63
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
64
  private
77
65
 
78
66
  def humanize_string(str)
@@ -29,8 +29,8 @@ module ISO3166
29
29
 
30
30
  def method_missing(method_name, *arguments)
31
31
  matches = method_name.to_s.match(FIND_BY_REGEX)
32
- return_all = matches[1]
33
32
  super unless matches
33
+ return_all = matches[1]
34
34
 
35
35
  countries = find_by(matches[3], arguments[0], matches[2])
36
36
  return_all ? countries : countries.last
@@ -72,8 +72,7 @@ module ISO3166
72
72
  end
73
73
 
74
74
  def searchable_attributes
75
- # Add name and names until we complete the deprecation of the finders
76
- instance_methods - UNSEARCHABLE_METHODS + %i[name names any_name]
75
+ instance_methods - UNSEARCHABLE_METHODS + %i[any_name]
77
76
  end
78
77
  end
79
78
  end
@@ -3,18 +3,19 @@
3
3
  module ISO3166
4
4
  class Country
5
5
  extend CountryClassMethods
6
+ extend ConversionMethods
6
7
  extend CountryFinderMethods
7
8
  include Emoji
8
9
  include CountrySubdivisionMethods
9
10
  attr_reader :data
10
11
 
11
- ISO3166::DEFAULT_COUNTRY_HASH.each do |method_name, _type|
12
+ ISO3166::DEFAULT_COUNTRY_HASH.each_key do |method_name|
12
13
  define_method method_name do
13
14
  data[method_name.to_s]
14
15
  end
15
16
  end
16
17
 
17
- ISO3166::DEFAULT_COUNTRY_HASH['geo'].each do |method_name, _type|
18
+ ISO3166::DEFAULT_COUNTRY_HASH['geo'].each_key do |method_name|
18
19
  define_method method_name do
19
20
  data['geo'][method_name.to_s]
20
21
  end
@@ -27,7 +27,6 @@ AM:
27
27
  iso_short_name: Armenia
28
28
  languages_official:
29
29
  - hy
30
- - ru
31
30
  languages_spoken:
32
31
  - hy
33
32
  - ru
@@ -38,6 +38,7 @@ AR:
38
38
  languages_spoken:
39
39
  - es
40
40
  - gn
41
+ - qu
41
42
  national_destination_code_lengths:
42
43
  - 2
43
44
  national_number_lengths:
@@ -53,6 +53,7 @@ BG:
53
53
  un_locode: BG
54
54
  unofficial_names:
55
55
  - Bulgaria
56
+ - България
56
57
  - Bulgarien
57
58
  - Bulgarie
58
59
  - ブルガリア
@@ -58,4 +58,5 @@ CD:
58
58
  - Congo (The Democratic Republic Of The)
59
59
  - Democratic Republic of the Congo
60
60
  - Congo, Democratic Republic of
61
+ - Congo (Kinshasa)
61
62
  world_region: EMEA
@@ -49,4 +49,5 @@ CG:
49
49
  - コンゴ共和国
50
50
  - Congo [Republiek]
51
51
  - Congo, Republic of
52
+ - Congo (Brazzaville)
52
53
  world_region: EMEA
@@ -35,10 +35,12 @@ CH:
35
35
  - de
36
36
  - fr
37
37
  - it
38
+ - rm
38
39
  languages_spoken:
39
40
  - de
40
41
  - fr
41
42
  - it
43
+ - rm
42
44
  national_destination_code_lengths:
43
45
  - 2
44
46
  national_number_lengths:
@@ -61,10 +63,10 @@ CH:
61
63
  - スイス
62
64
  - Zwitserland
63
65
  vat_rates:
64
- standard: 7.7
66
+ standard: 8.1
65
67
  reduced:
66
- - 2.5
67
- - 3.7
68
+ - 2.6
69
+ - 3.8
68
70
  super_reduced:
69
71
  parking:
70
72
  world_region: EMEA
@@ -51,7 +51,7 @@ EE:
51
51
  - Estonie
52
52
  - エストニア
53
53
  vat_rates:
54
- standard: 20
54
+ standard: 22
55
55
  reduced:
56
56
  - 9
57
57
  super_reduced:
@@ -4,7 +4,7 @@ ER:
4
4
  alpha3: ERI
5
5
  continent: Africa
6
6
  country_code: '291'
7
- currency_code: ETB
7
+ currency_code: ERN
8
8
  distance_unit: KM
9
9
  gec: ER
10
10
  geo:
@@ -37,6 +37,14 @@ ES:
37
37
  - es
38
38
  languages_spoken:
39
39
  - es
40
+ - ca
41
+ - gl
42
+ - eu
43
+ - an
44
+ - ast
45
+ - fax
46
+ - rif
47
+ - rmq
40
48
  national_destination_code_lengths:
41
49
  - 2
42
50
  national_number_lengths:
@@ -58,7 +58,7 @@ FI:
58
58
  - Finlandia
59
59
  - フィンランド
60
60
  vat_rates:
61
- standard: 24
61
+ standard: 25.5
62
62
  reduced:
63
63
  - 10
64
64
  - 14
@@ -29,7 +29,6 @@ FJ:
29
29
  - en
30
30
  - fj
31
31
  - hi
32
- - ur
33
32
  languages_spoken:
34
33
  - en
35
34
  - fj
@@ -71,6 +71,7 @@ GB:
71
71
  - Velká Británie
72
72
  - İngiltere
73
73
  - Великобританія
74
+ - Great Britain
74
75
  vat_rates:
75
76
  standard: 20
76
77
  reduced:
@@ -46,4 +46,5 @@ MM:
46
46
  unofficial_names:
47
47
  - Myanmar (Burma)
48
48
  - ミャンマー
49
+ - Burma
49
50
  world_region: APAC
@@ -36,6 +36,7 @@ NL:
36
36
  - nl
37
37
  languages_spoken:
38
38
  - nl
39
+ - fy
39
40
  national_destination_code_lengths:
40
41
  - 2
41
42
  national_number_lengths:
@@ -39,7 +39,7 @@ PY:
39
39
  nationality: Paraguayan
40
40
  number: '600'
41
41
  postal_code: true
42
- postal_code_format: "\\d{4}"
42
+ postal_code_format: "\\d{6}"
43
43
  region: Americas
44
44
  start_of_week: monday
45
45
  subregion: South America
@@ -27,7 +27,6 @@ UZ:
27
27
  iso_short_name: Uzbekistan
28
28
  languages_official:
29
29
  - uz
30
- - ru
31
30
  languages_spoken:
32
31
  - uz
33
32
  - ru
@@ -9029,7 +9029,7 @@ PTE:
9029
9029
  max_latitude: 52.6637708
9030
9030
  max_longitude: -0.1032429
9031
9031
  translations:
9032
- en: Peter
9032
+ en: Peterborough
9033
9033
  af: Peterborough
9034
9034
  ar: بيتربرة
9035
9035
  bn: পিটারবার্গ
@@ -1,7 +1,7 @@
1
1
  ---
2
- AV:
2
+ '16':
3
3
  name: Alta Verapaz
4
- code: AV
4
+ code: '16'
5
5
  unofficial_names: Alta Verapaz
6
6
  geo:
7
7
  latitude: 15.5942883
@@ -61,9 +61,9 @@ AV:
61
61
  'no': Alta Verapaz
62
62
  comments:
63
63
  type: department
64
- BV:
64
+ '15':
65
65
  name: Baja Verapaz
66
- code: BV
66
+ code: '15'
67
67
  unofficial_names: Baja Verapaz
68
68
  geo:
69
69
  latitude: 15.0787498
@@ -122,9 +122,9 @@ BV:
122
122
  'no': Baja Verapaz
123
123
  comments:
124
124
  type: department
125
- CM:
125
+ '04':
126
126
  name: Chimaltenango
127
- code: CM
127
+ code: '04'
128
128
  unofficial_names: Chimaltenango
129
129
  geo:
130
130
  latitude: 14.662222
@@ -183,9 +183,9 @@ CM:
183
183
  'no': Chimaltenango
184
184
  comments:
185
185
  type: department
186
- CQ:
186
+ '20':
187
187
  name: Chiquimula
188
- code: CQ
188
+ code: '20'
189
189
  unofficial_names: Chiquimula
190
190
  geo:
191
191
  latitude: 14.783333
@@ -242,9 +242,9 @@ CQ:
242
242
  'no': Chiquimula
243
243
  comments:
244
244
  type: department
245
- ES:
245
+ '05':
246
246
  name: Escuintla
247
- code: ES
247
+ code: '05'
248
248
  unofficial_names: Escuintla
249
249
  geo:
250
250
  latitude: 14.3009389
@@ -302,9 +302,9 @@ ES:
302
302
  'no': Escuintla
303
303
  comments:
304
304
  type: department
305
- GU:
305
+ '01':
306
306
  name: Guatemala
307
- code: GU
307
+ code: '01'
308
308
  unofficial_names: Guatemala
309
309
  geo:
310
310
  latitude: 14.613333
@@ -365,9 +365,9 @@ GU:
365
365
  'no': Guatemala
366
366
  comments:
367
367
  type: department
368
- HU:
368
+ '13':
369
369
  name: Huehuetenango
370
- code: HU
370
+ code: '13'
371
371
  unofficial_names: Huehuetenango
372
372
  geo:
373
373
  latitude: 15.314722
@@ -425,9 +425,9 @@ HU:
425
425
  'no': Huehuetenango
426
426
  comments:
427
427
  type: department
428
- IZ:
428
+ '18':
429
429
  name: Izabal
430
- code: IZ
430
+ code: '18'
431
431
  unofficial_names: Izabal
432
432
  geo:
433
433
  latitude: 15.4036847
@@ -485,9 +485,9 @@ IZ:
485
485
  'no': Izabal
486
486
  comments:
487
487
  type: department
488
- JA:
488
+ '21':
489
489
  name: Jalapa
490
- code: JA
490
+ code: '21'
491
491
  unofficial_names: Jalapa
492
492
  geo:
493
493
  latitude: 14.5655154
@@ -545,9 +545,9 @@ JA:
545
545
  'no': Jalapa
546
546
  comments:
547
547
  type: department
548
- JU:
548
+ '22':
549
549
  name: Jutiapa
550
- code: JU
550
+ code: '22'
551
551
  unofficial_names: Jutiapa
552
552
  geo:
553
553
  latitude: 14.282778
@@ -606,9 +606,9 @@ JU:
606
606
  'no': Jutiapa
607
607
  comments:
608
608
  type: department
609
- PE:
609
+ '17':
610
610
  name: Petén
611
- code: PE
611
+ code: '17'
612
612
  unofficial_names: Petén
613
613
  geo:
614
614
  latitude: 16.912033
@@ -668,9 +668,9 @@ PE:
668
668
  'no': Petén
669
669
  comments:
670
670
  type: department
671
- PR:
671
+ '02':
672
672
  name: El Progreso
673
- code: PR
673
+ code: '02'
674
674
  unofficial_names: El Progreso
675
675
  geo:
676
676
  latitude: 14.86527
@@ -728,9 +728,9 @@ PR:
728
728
  'no': El Progreso
729
729
  comments:
730
730
  type: department
731
- QC:
731
+ '14':
732
732
  name: Quiché
733
- code: QC
733
+ code: '14'
734
734
  unofficial_names: Quiché
735
735
  geo:
736
736
  latitude: 15.4983808
@@ -788,9 +788,9 @@ QC:
788
788
  'no': Quiché
789
789
  comments:
790
790
  type: department
791
- QZ:
791
+ '09':
792
792
  name: Quetzaltenango
793
- code: QZ
793
+ code: '09'
794
794
  unofficial_names:
795
795
  - Quetzaltenango
796
796
  geo:
@@ -851,9 +851,9 @@ QZ:
851
851
  'no': Quetzaltenango
852
852
  comments:
853
853
  type: department
854
- RE:
854
+ '11':
855
855
  name: Retalhuleu
856
- code: RE
856
+ code: '11'
857
857
  unofficial_names: Retalhuleu
858
858
  geo:
859
859
  latitude: 14.533333
@@ -912,9 +912,9 @@ RE:
912
912
  'no': Retalhuleu
913
913
  comments:
914
914
  type: department
915
- SA:
915
+ '03':
916
916
  name: Sacatepéquez
917
- code: SA
917
+ code: '03'
918
918
  unofficial_names: Sacatepéquez
919
919
  geo:
920
920
  latitude: 14.6110576
@@ -974,9 +974,9 @@ SA:
974
974
  'no': Sacatepéquez
975
975
  comments:
976
976
  type: department
977
- SM:
977
+ '12':
978
978
  name: San Marcos
979
- code: SM
979
+ code: '12'
980
980
  unofficial_names: San Marcos
981
981
  geo:
982
982
  latitude: 14.9309569
@@ -1034,9 +1034,9 @@ SM:
1034
1034
  'no': San Marcos (departement)
1035
1035
  comments:
1036
1036
  type: department
1037
- SO:
1037
+ '07':
1038
1038
  name: Sololá
1039
- code: SO
1039
+ code: '07'
1040
1040
  unofficial_names: Sololá
1041
1041
  geo:
1042
1042
  latitude: 14.773889
@@ -1094,9 +1094,9 @@ SO:
1094
1094
  'no': Sololá
1095
1095
  comments:
1096
1096
  type: department
1097
- SR:
1097
+ '06':
1098
1098
  name: Santa Rosa
1099
- code: SR
1099
+ code: '06'
1100
1100
  unofficial_names: Santa Rosa
1101
1101
  geo:
1102
1102
  latitude: 14.1928003
@@ -1156,9 +1156,9 @@ SR:
1156
1156
  'no': Santa Rosa (departement)
1157
1157
  comments:
1158
1158
  type: department
1159
- SU:
1159
+ '10':
1160
1160
  name: Suchitepéquez
1161
- code: SU
1161
+ code: '10'
1162
1162
  unofficial_names: Suchitepéquez
1163
1163
  geo:
1164
1164
  latitude: 14.4215982
@@ -1216,9 +1216,9 @@ SU:
1216
1216
  'no': Suchitepéquez
1217
1217
  comments:
1218
1218
  type: department
1219
- TO:
1219
+ '08':
1220
1220
  name: Totonicapán
1221
- code: TO
1221
+ code: '08'
1222
1222
  unofficial_names: Totonicapán
1223
1223
  geo:
1224
1224
  latitude: 14.910833
@@ -1276,9 +1276,9 @@ TO:
1276
1276
  'no': Totonicapán (departement)
1277
1277
  comments:
1278
1278
  type: department
1279
- ZA:
1279
+ '19':
1280
1280
  name: Zacapa
1281
- code: ZA
1281
+ code: '19'
1282
1282
  unofficial_names: Zacapa
1283
1283
  geo:
1284
1284
  latitude: 15.0784265
@@ -98,8 +98,8 @@ module ISO3166
98
98
  end
99
99
  end
100
100
 
101
- def synchronized(&block)
102
- @mutex.synchronize(&block)
101
+ def synchronized(&)
102
+ @mutex.synchronize(&)
103
103
  end
104
104
 
105
105
  def load_required?
@@ -11,6 +11,7 @@ require 'countries/structure'
11
11
  require 'countries/translations'
12
12
  require 'countries/country/country_subdivision_methods'
13
13
  require 'countries/country/class_methods'
14
+ require 'countries/country/conversion_methods'
14
15
  require 'countries/country/finder_methods'
15
16
  require 'countries/country/emoji'
16
17
  require 'countries/country'
@@ -24,7 +24,7 @@ module Sources
24
24
  last_country_code_seen = nil
25
25
 
26
26
  subdivisions.each_with_index do |subdivision, index|
27
- subdivision = Sources::CLDR::Subdivision.new(language_code: language_code, xml: subdivision)
27
+ subdivision = Sources::CLDR::Subdivision.new(language_code:, xml: subdivision)
28
28
  data = @loader.load(subdivision.country_code)
29
29
  data[subdivision.code] ||= {}
30
30
  data[subdivision.code] = data[subdivision.code].deep_merge(subdivision.to_h)
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './sources/local/cached_loader'
4
- require_relative './sources/local/subdivision'
3
+ require_relative 'sources/local/cached_loader'
4
+ require_relative 'sources/local/subdivision'
5
5
 
6
- require_relative './sources/cldr/downloader'
7
- require_relative './sources/cldr/subdivision'
8
- require_relative './sources/cldr/subdivision_updater'
6
+ require_relative 'sources/cldr/downloader'
7
+ require_relative 'sources/cldr/subdivision'
8
+ require_relative 'sources/cldr/subdivision_updater'
@@ -7,7 +7,7 @@ module ISO3166
7
7
  # to +pt+ to prevent from showing nil values
8
8
  class Translations < Hash
9
9
  def [](locale)
10
- super(locale) || super(locale.to_s.sub(/-.*/, ''))
10
+ super || super(locale.to_s.sub(/-.*/, ''))
11
11
  end
12
12
  end
13
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Countries
4
- VERSION = '6.0.0'
4
+ VERSION = '7.0.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: countries
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 7.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Robinson
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2024-02-17 00:00:00.000000000 Z
14
+ date: 2024-09-29 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: unaccent
@@ -229,6 +229,7 @@ files:
229
229
  - lib/countries/configuration.rb
230
230
  - lib/countries/country.rb
231
231
  - lib/countries/country/class_methods.rb
232
+ - lib/countries/country/conversion_methods.rb
232
233
  - lib/countries/country/country_subdivision_methods.rb
233
234
  - lib/countries/country/currency_methods.rb
234
235
  - lib/countries/country/emoji.rb
@@ -848,14 +849,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
848
849
  requirements:
849
850
  - - ">="
850
851
  - !ruby/object:Gem::Version
851
- version: '3.0'
852
+ version: '3.1'
852
853
  required_rubygems_version: !ruby/object:Gem::Requirement
853
854
  requirements:
854
855
  - - ">="
855
856
  - !ruby/object:Gem::Version
856
857
  version: '0'
857
858
  requirements: []
858
- rubygems_version: 3.5.4
859
+ rubygems_version: 3.5.16
859
860
  signing_key:
860
861
  specification_version: 4
861
862
  summary: Gives you a country object full of all sorts of useful information.