countries 4.2.3 → 5.0.2

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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/codeql-analysis.yml +70 -0
  3. data/.github/workflows/tests.yml +3 -7
  4. data/.rubocop.yml +40 -1
  5. data/.rubocop_todo.yml +8 -41
  6. data/CHANGELOG.md +21 -2
  7. data/Gemfile +5 -3
  8. data/README.markdown +48 -60
  9. data/Rakefile +13 -31
  10. data/UPGRADE.md +26 -0
  11. data/bin/console +1 -0
  12. data/countries.gemspec +7 -5
  13. data/lib/countries/cache/countries.json +1 -1
  14. data/lib/countries/cache/locales/en.json +1 -1
  15. data/lib/countries/configuration.rb +2 -0
  16. data/lib/countries/country/class_methods.rb +12 -97
  17. data/lib/countries/country/currency_methods.rb +2 -0
  18. data/lib/countries/country/emoji.rb +2 -3
  19. data/lib/countries/country/finder_methods.rb +81 -0
  20. data/lib/countries/country.rb +3 -40
  21. data/lib/countries/data/countries/KN.yaml +0 -1
  22. data/lib/countries/data/subdivisions/MX.yaml +3 -15
  23. data/lib/countries/data/subdivisions/PT.yaml +13 -13
  24. data/lib/countries/data/translation_corrections.yaml +2 -0
  25. data/lib/countries/data.rb +34 -37
  26. data/lib/countries/global.rb +2 -0
  27. data/lib/countries/iso3166.rb +3 -0
  28. data/lib/countries/kwarg_struct.rb +2 -0
  29. data/lib/countries/mongoid.rb +2 -0
  30. data/lib/countries/sources/cldr/downloader.rb +8 -8
  31. data/lib/countries/sources/cldr/subdivision.rb +3 -0
  32. data/lib/countries/sources/cldr/subdivision_updater.rb +23 -17
  33. data/lib/countries/sources/local/cached_loader.rb +3 -0
  34. data/lib/countries/sources/local/subdivision.rb +5 -2
  35. data/lib/countries/sources.rb +2 -0
  36. data/lib/countries/structure.rb +1 -1
  37. data/lib/countries/subdivision.rb +2 -0
  38. data/lib/countries/tasks/geocoding.rake +15 -6
  39. data/lib/countries/tasks/postal_codes.rake +5 -3
  40. data/lib/countries/timezones.rb +5 -2
  41. data/lib/countries/translations.rb +2 -0
  42. data/lib/countries/version.rb +3 -1
  43. data/lib/countries.rb +2 -0
  44. data/spec/00_global_spec.rb +2 -0
  45. data/spec/configuration_spec.rb +11 -5
  46. data/spec/country_spec.rb +71 -22
  47. data/spec/data_spec.rb +24 -18
  48. data/spec/mongoid_spec.rb +2 -2
  49. data/spec/perf_spec.rb +16 -16
  50. data/spec/spec_helper.rb +2 -0
  51. data/spec/subdivision_spec.rb +6 -4
  52. data/spec/thread_safety_spec.rb +4 -3
  53. data/spec/timezone_spec.rb +2 -0
  54. metadata +15 -12
  55. data/lib/countries/setup.rb +0 -18
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ISO3166
2
4
  # Handles building the in memory store of countries data
3
5
  class Data
4
- @@cache_dir = [File.dirname(__FILE__), 'cache']
5
- @@cache = {}
6
- @@registered_data = {}
7
- @@mutex = Mutex.new
6
+ @cache_dir = [File.dirname(__FILE__), 'cache']
7
+ @cache = {}
8
+ @registered_data = {}
9
+ @mutex = Mutex.new
8
10
 
9
11
  def initialize(alpha2)
10
12
  @alpha2 = alpha2.to_s.upcase
@@ -15,30 +17,23 @@ module ISO3166
15
17
  end
16
18
 
17
19
  class << self
18
- def cache_dir
19
- @@cache_dir
20
- end
21
-
22
- def cache_dir=(value)
23
- @@cache_dir = value
24
- end
25
20
 
26
21
  # Registers a new Country with custom data.
27
22
  # If you are overriding an existing country, this does not perform a deep merge so you will need to __bring in all data you wish to be available__.
28
23
  # Overriding an existing country will also remove it from the internal management of translations.
29
24
  def register(data)
30
25
  alpha2 = data[:alpha2].upcase
31
- @@registered_data[alpha2] = deep_stringify_keys(data)
32
- @@registered_data[alpha2]['translations'] = \
26
+ @registered_data[alpha2] = deep_stringify_keys(data)
27
+ @registered_data[alpha2]['translations'] = \
33
28
  Translations.new.merge(data['translations'] || {})
34
- @@cache = cache.merge(@@registered_data)
29
+ @cache = cache.merge(@registered_data)
35
30
  end
36
31
 
37
32
  # Removes a country from the loaded data
38
33
  def unregister(alpha2)
39
34
  alpha2 = alpha2.to_s.upcase
40
- @@cache.delete(alpha2)
41
- @@registered_data.delete(alpha2)
35
+ @cache.delete(alpha2)
36
+ @registered_data.delete(alpha2)
42
37
  end
43
38
 
44
39
  def cache
@@ -47,8 +42,8 @@ module ISO3166
47
42
 
48
43
  # Resets the loaded data and cache
49
44
  def reset
50
- @@cache = {}
51
- @@registered_data = {}
45
+ @cache = {}
46
+ @registered_data = {}
52
47
  ISO3166.configuration.loaded_locales = []
53
48
  end
54
49
 
@@ -60,16 +55,19 @@ module ISO3166
60
55
  def update_cache
61
56
  load_data!
62
57
  sync_translations!
63
- @@cache
58
+ @cache
64
59
  end
65
60
 
61
+ private
62
+
66
63
  def load_data!
67
- return @@cache unless load_required?
64
+ return @cache unless load_required?
65
+
68
66
  synchronized do
69
- @@cache = load_cache %w(countries.json)
70
- @@_country_codes = @@cache.keys
71
- @@cache = @@cache.merge(@@registered_data)
72
- @@cache
67
+ @cache = load_cache %w[countries.json]
68
+ @_country_codes = @cache.keys
69
+ @cache = @cache.merge(@registered_data)
70
+ @cache
73
71
  end
74
72
  end
75
73
 
@@ -85,11 +83,9 @@ module ISO3166
85
83
  end
86
84
  end
87
85
 
88
- private
89
-
90
86
  def synchronized(&block)
91
87
  if use_mutex?
92
- @@mutex.synchronize(&block)
88
+ @mutex.synchronize(&block)
93
89
  else
94
90
  block.call
95
91
  end
@@ -102,17 +98,17 @@ module ISO3166
102
98
 
103
99
  def load_required?
104
100
  synchronized do
105
- @@cache.empty?
101
+ @cache.empty?
106
102
  end
107
103
  end
108
104
 
109
105
  def loaded_codes
110
- @@cache.keys
106
+ @cache.keys
111
107
  end
112
108
 
113
109
  # Codes that we have translations for in dataset
114
110
  def internal_codes
115
- @@_country_codes - @@registered_data.keys
111
+ @_country_codes - @registered_data.keys
116
112
  end
117
113
 
118
114
  def cache_flush_required?
@@ -139,9 +135,9 @@ module ISO3166
139
135
  synchronized do
140
136
  locale_names = load_cache(['locales', "#{locale}.json"])
141
137
  internal_codes.each do |alpha2|
142
- @@cache[alpha2]['translations'] ||= Translations.new
143
- @@cache[alpha2]['translations'][locale] = locale_names[alpha2].freeze
144
- @@cache[alpha2]['translated_names'] = @@cache[alpha2]['translations'].values.freeze
138
+ @cache[alpha2]['translations'] ||= Translations.new
139
+ @cache[alpha2]['translations'][locale] = locale_names[alpha2].freeze
140
+ @cache[alpha2]['translated_names'] = @cache[alpha2]['translations'].values.freeze
145
141
  end
146
142
  ISO3166.configuration.loaded_locales << locale
147
143
  end
@@ -150,8 +146,8 @@ module ISO3166
150
146
  def unload_translations(locale)
151
147
  synchronized do
152
148
  internal_codes.each do |alpha2|
153
- @@cache[alpha2]['translations'].delete(locale)
154
- @@cache[alpha2]['translated_names'] = @@cache[alpha2]['translations'].values.freeze
149
+ @cache[alpha2]['translations'].delete(locale)
150
+ @cache[alpha2]['translated_names'] = @cache[alpha2]['translations'].values.freeze
155
151
  end
156
152
  ISO3166.configuration.loaded_locales.delete(locale)
157
153
  end
@@ -163,7 +159,7 @@ module ISO3166
163
159
  end
164
160
 
165
161
  def datafile_path(file_array)
166
- File.join([@@cache_dir] + file_array)
162
+ File.join([@cache_dir] + file_array)
167
163
  end
168
164
 
169
165
  def deep_stringify_keys(data)
@@ -171,7 +167,8 @@ module ISO3166
171
167
  data.transform_values! do |v|
172
168
  v.is_a?(Hash) ? deep_stringify_keys(v) : v
173
169
  end
174
- return data
170
+
171
+ data
175
172
  end
176
173
  end
177
174
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'countries'
2
4
 
3
5
  # Some apps might not want to constantly call +ISO3166::Country+. This gem has a helper that can provide a Country class
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'json'
3
5
  require 'i18n_data'
@@ -8,6 +10,7 @@ require 'countries/data'
8
10
  require 'countries/structure'
9
11
  require 'countries/translations'
10
12
  require 'countries/country/class_methods'
13
+ require 'countries/country/finder_methods'
11
14
  require 'countries/country/emoji'
12
15
  require 'countries/country'
13
16
  require 'countries/subdivision'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ISO3166
2
4
  class KwargStruct < Struct
3
5
  # Override the initialize to handle hashes of named parameters
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ISO3166
2
4
  class Country
3
5
  def mongoize
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
  require 'net/http'
3
5
  require 'nokogiri'
@@ -19,19 +21,17 @@ module Sources
19
21
  def download_folder(type)
20
22
  folder = File.join(ISO3166_ROOT_PATH, 'tmp', 'cldr', 'trunk', 'common', type)
21
23
  FileUtils.mkdir_p(folder)
22
- url = URI.parse("https://api.github.com/repos/unicode-org/cldr/contents/common/" + type)
24
+ url = URI.parse("https://api.github.com/repos/unicode-org/cldr/contents/common/#{type}")
23
25
  path_listing = JSON.parse(Net::HTTP.get_response(url).body)
24
26
  path_listing.each do |path|
25
- if path['name'] =~ /\.xml$/
26
- File.open(File.join(folder, path['name']), 'w') do |f|
27
- raw_url = URI.parse(path['download_url'])
28
- f.write(Net::HTTP.get_response(raw_url).body)
29
- end
27
+ next unless path['name'] =~ /\.xml$/
28
+
29
+ File.open(File.join(folder, path['name']), 'w') do |f|
30
+ raw_url = URI.parse(path['download_url'])
31
+ f.write(Net::HTTP.get_response(raw_url).body)
30
32
  end
31
33
  end
32
34
  end
33
-
34
35
  end
35
36
  end
36
37
  end
37
-
@@ -1,8 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sources
2
4
  module CLDR
3
5
  # Auxiliary Subdivision class to support loading Unicode CLDR data to update local files
4
6
  class Subdivision
5
7
  attr_reader :xml, :language_code
8
+
6
9
  def initialize(language_code:, xml:)
7
10
  @language_code = language_code
8
11
  @xml = xml
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support'
2
4
  require 'active_support/core_ext/hash/deep_merge'
3
5
  require 'nokogiri'
@@ -9,25 +11,29 @@ module Sources
9
11
  class SubdivisionUpdater
10
12
  def call
11
13
  d = Dir['./tmp/cldr/trunk/common/subdivisions/*.xml']
12
- loader = Sources::Local::CachedLoader.new(Sources::Local::Subdivision)
13
- d.each do |file_path|
14
- language_data = Nokogiri::XML(File.read(file_path))
15
- language_code = File.basename(file_path, '.*')
16
- subdivisions = language_data.css('subdivision')
17
- next if subdivisions.empty?
18
- last_country_code_seen = nil
14
+ @loader = Sources::Local::CachedLoader.new(Sources::Local::Subdivision)
15
+ d.each { |file_path| update_locale(file_path) }
16
+ end
17
+
18
+ def update_locale(file_path)
19
+ language_data = Nokogiri::XML(File.read(file_path))
20
+ language_code = File.basename(file_path, '.*')
21
+ subdivisions = language_data.css('subdivision')
22
+ next if subdivisions.empty?
23
+
24
+ last_country_code_seen = nil
19
25
 
20
- subdivisions.each_with_index do |subdivision, index|
21
- subdivision = Sources::CLDR::Subdivision.new(language_code: language_code, xml: subdivision)
22
- data = loader.load(subdivision.country_code)
23
- data[subdivision.code] ||= {}
24
- data[subdivision.code] = data[subdivision.code].deep_merge(subdivision.to_h)
25
- if (last_country_code_seen && last_country_code_seen != subdivision.country_code) || index == subdivisions.size - 1
26
- puts "Updated #{subdivision.country_code} with language_code #{language_code}"
27
- loader.save(subdivision.country_code, data)
28
- end
29
- last_country_code_seen = subdivision.country_code
26
+ subdivisions.each_with_index do |subdivision, index|
27
+ subdivision = Sources::CLDR::Subdivision.new(language_code: language_code, xml: subdivision)
28
+ data = @loader.load(subdivision.country_code)
29
+ data[subdivision.code] ||= {}
30
+ data[subdivision.code] = data[subdivision.code].deep_merge(subdivision.to_h)
31
+ if (last_country_code_seen && last_country_code_seen != subdivision.country_code) ||
32
+ index == subdivisions.size - 1
33
+ puts "Updated #{subdivision.country_code} with language_code #{language_code}"
34
+ @loader.save(subdivision.country_code, data)
30
35
  end
36
+ last_country_code_seen = subdivision.country_code
31
37
  end
32
38
  end
33
39
  end
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sources
2
4
  # Support code to allow updating subdivision data from the Unicode CLDR repository
3
5
  module Local
4
6
  # Loader for locally-cached data, to allow merging Unicode CLDR data with existing local data
5
7
  class CachedLoader
6
8
  attr_reader :klass
9
+
7
10
  def initialize(klass)
8
11
  @klass = klass
9
12
  @loaded_countries = {}
@@ -1,8 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sources
2
4
  module Local
3
5
  # Auxiliary Subdivision class to support loading the local subdivision data to be updated with Unicode CLDR data
4
6
  class Subdivision
5
7
  attr_reader :code
8
+
6
9
  def initialize(code)
7
10
  @code = code
8
11
  end
@@ -16,8 +19,8 @@ module Sources
16
19
  end
17
20
 
18
21
  def save(data)
19
- File.open(file_path, 'w') { |f| f.write data.to_yaml }
20
- rescue
22
+ File.write(file_path, data.to_yaml)
23
+ rescue StandardError
21
24
  puts "failed to read #{file}: #{$ERROR_INFO}"
22
25
  end
23
26
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './sources/local/cached_loader'
2
4
  require_relative './sources/local/subdivision'
3
5
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- #
2
+
3
3
  module ISO3166
4
4
  DEFAULT_COUNTRY_HASH = {
5
5
  'address_format' => nil,
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ISO3166
2
4
  Subdivision = KwargStruct.new(
3
5
  :name,
@@ -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.open(File.join(ISO3166_ROOT_PATH, 'lib', 'countries', 'data', 'countries', "#{alpha2}.yaml"), 'w+') { |f| f.write data.to_yaml }
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
- puts "WARNING:: Geocoder returned something that was not a country for #{country.alpha2}" unless result.types.include?('country')
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, data|
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.open(File.join(ISO3166_ROOT_PATH, 'lib', 'countries', 'data', 'subdivisions', "#{c.alpha2}.yaml"), 'w+') { |f| f.write state_data.to_yaml }
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', !!json['zip']]
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.open(country_file, 'w') { |file| file.write(yaml.to_yaml) }
47
+ File.write(country_file, yaml.to_yaml)
46
48
  end
47
49
  end
48
50
  end
@@ -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
- @tz_country ||= TZInfo::Country.get(alpha2)
11
+ @timezones ||= TZInfo::Country.get(alpha2)
9
12
  end
10
13
  end
11
14
  end
12
15
 
13
- ISO3166::Country.send(:include, ISO3166::TimezoneExtensions)
16
+ ISO3166::Country.include ISO3166::TimezoneExtensions
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ISO3166
2
4
  # Extend the hash class to allow locale lookup fall back behavior
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Countries
2
- VERSION = '4.2.3'.freeze
4
+ VERSION = '5.0.2'.freeze
3
5
  end
data/lib/countries.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sixarm_ruby_unaccent'
2
4
 
3
5
  require 'countries/version'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  describe 'global Country class', order: :defined do
2
4
  context "when loaded via 'iso3166' existence" do
3
5
  subject { defined?(Country) }
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
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 = [:de, :en]
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 = [:de, :en, :unsupported]
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 = [:es, :de, :en]
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 = [:af, :am, :ar, :as, :az, :be, :bg, :bn, :br, :bs, :ca, :cs, :cy, :da, :de, :dz, :el, :en, :eo, :es, :et, :eu, :fa, :fi, :fo, :fr, :ga, :gl, :gu, :he, :hi, :hr, :hu, :hy, :ia, :id, :is, :it, :ja, :ka, :kk, :km, :kn, :ko, :ku, :lt, :lv, :mi, :mk, :ml, :mn, :mr, :ms, :mt, :nb, :ne, :nl, :nn, :oc, :or, :pa, :pl, :ps, :pt, :ro, :ru, :rw, :si, :sk, :sl, :so, :sq, :sr, :sv, :sw, :ta, :te, :th, :ti, :tk, :tl, :tr, :tt, :ug, :uk, :ve, :vi, :wa, :wo, :xh, :zh, :zu]
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