countries 5.7.0 → 5.7.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile DELETED
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
- gem 'money'
5
- gem 'rake'
6
- gem 'retryable'
7
- gem 'tzinfo'
8
-
9
- # Specify your gem's dependencies in countries.gemspec
10
- gemspec
11
-
12
- group :development, :test do
13
- gem 'debug'
14
- gem 'yaml'
15
- end
data/Gemfile.lock DELETED
@@ -1,102 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- countries (5.7.0)
5
- unaccent (~> 0.3)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activesupport (7.1.0)
11
- base64
12
- bigdecimal
13
- concurrent-ruby (~> 1.0, >= 1.0.2)
14
- connection_pool (>= 2.2.5)
15
- drb
16
- i18n (>= 1.6, < 2)
17
- minitest (>= 5.1)
18
- mutex_m
19
- tzinfo (~> 2.0)
20
- base64 (0.1.1)
21
- bigdecimal (3.1.4)
22
- concurrent-ruby (1.2.2)
23
- connection_pool (2.4.1)
24
- debug (1.8.0)
25
- irb (>= 1.5.0)
26
- reline (>= 0.3.1)
27
- diff-lcs (1.5.0)
28
- docile (1.4.0)
29
- drb (2.1.1)
30
- ruby2_keywords
31
- i18n (1.14.1)
32
- concurrent-ruby (~> 1.0)
33
- io-console (0.6.0)
34
- irb (1.8.1)
35
- rdoc
36
- reline (>= 0.3.8)
37
- minitest (5.20.0)
38
- money (6.16.0)
39
- i18n (>= 0.6.4, <= 2)
40
- mutex_m (0.1.2)
41
- nokogiri (1.15.4-arm64-darwin)
42
- racc (~> 1.4)
43
- nokogiri (1.15.4-x86_64-darwin)
44
- racc (~> 1.4)
45
- nokogiri (1.15.4-x86_64-linux)
46
- racc (~> 1.4)
47
- psych (5.1.0)
48
- stringio
49
- racc (1.7.1)
50
- rake (13.0.6)
51
- rdoc (6.5.0)
52
- psych (>= 4.0.0)
53
- reline (0.3.9)
54
- io-console (~> 0.5)
55
- retryable (3.0.5)
56
- rspec (3.12.0)
57
- rspec-core (~> 3.12.0)
58
- rspec-expectations (~> 3.12.0)
59
- rspec-mocks (~> 3.12.0)
60
- rspec-core (3.12.2)
61
- rspec-support (~> 3.12.0)
62
- rspec-expectations (3.12.3)
63
- diff-lcs (>= 1.2.0, < 2.0)
64
- rspec-support (~> 3.12.0)
65
- rspec-mocks (3.12.6)
66
- diff-lcs (>= 1.2.0, < 2.0)
67
- rspec-support (~> 3.12.0)
68
- rspec-support (3.12.1)
69
- ruby2_keywords (0.0.5)
70
- simplecov (0.22.0)
71
- docile (~> 1.1)
72
- simplecov-html (~> 0.11)
73
- simplecov_json_formatter (~> 0.1)
74
- simplecov-html (0.12.3)
75
- simplecov_json_formatter (0.1.4)
76
- stringio (3.0.8)
77
- tzinfo (2.0.6)
78
- concurrent-ruby (~> 1.0)
79
- unaccent (0.4.0)
80
- yaml (0.2.1)
81
-
82
- PLATFORMS
83
- arm64-darwin-22
84
- x86_64-darwin-21
85
- x86_64-darwin-22
86
- x86_64-linux
87
-
88
- DEPENDENCIES
89
- activesupport (>= 3)
90
- countries!
91
- debug
92
- money
93
- nokogiri (>= 1.8)
94
- rake
95
- retryable
96
- rspec (>= 3)
97
- simplecov (~> 0.22)
98
- tzinfo
99
- yaml
100
-
101
- BUNDLED WITH
102
- 2.4.12
data/LICENSE DELETED
@@ -1,24 +0,0 @@
1
- Copyright (c) 2012-2015 hexorx
2
- Copyright (c) 2015-2021 hexorx, rposborne
3
- Copyright (c) 2022 hexorx, rposborne, pmor
4
-
5
- MIT License
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining
8
- a copy of this software and associated documentation files (the
9
- "Software"), to deal in the Software without restriction, including
10
- without limitation the rights to use, copy, modify, merge, publish,
11
- distribute, sublicense, and/or sell copies of the Software, and to
12
- permit persons to whom the Software is furnished to do so, subject to
13
- the following conditions:
14
-
15
- The above copyright notice and this permission notice shall be
16
- included in all copies or substantial portions of the Software.
17
-
18
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,404 +0,0 @@
1
- # Countries
2
-
3
- Countries is a collection of all sorts of useful information for every country in the ISO 3166 standard. It contains info for the following standards ISO3166-1 (countries), ISO3166-2 (states/subdivisions), ISO4217 (currency) and E.164 (phone numbers).
4
-
5
- The data used in this gem is also available as git submodules in [YAML](https://github.com/countries/countries-data-yaml) and [JSON](https://github.com/countries/countries-data-json) files.
6
-
7
- [![Gem Version](https://badge.fury.io/rb/countries.svg)](https://badge.fury.io/rb/countries) [![Tests](https://github.com/countries/countries/actions/workflows/tests.yml/badge.svg)](https://github.com/countries/countries/actions/workflows/tests.yml) [![Code Climate](https://codeclimate.com/github/countries/countries.svg)](https://codeclimate.com/github/countries/countries)
8
- [![CodeQL](https://github.com/countries/countries/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/countries/countries/actions/workflows/codeql-analysis.yml)
9
-
10
-
11
- ## Installation
12
-
13
- ```bash
14
- gem install countries
15
- ```
16
-
17
- Or you can install via Bundler if you are using Rails:
18
-
19
- ```bash
20
- bundle add countries
21
- ```
22
-
23
- ## Basic Usage
24
-
25
- Simply load a new country object using Country.new(*alpha2*) or the shortcut Country[*alpha2*]. An example works best.
26
-
27
- ```ruby
28
- c = ISO3166::Country.new('US')
29
- ```
30
-
31
- Get all country codes (*alpha2*).
32
-
33
- ```ruby
34
- ISO3166::Country.codes
35
- # ["TJ", "JM", "HT",...]
36
- ```
37
-
38
- ## Configuration
39
-
40
- ### Country Helper
41
-
42
- Some apps might not want to constantly call `ISO3166::Country` this gem has a
43
- helper that can provide a `Country` class
44
-
45
- ```ruby
46
- # With global Country Helper
47
- c = Country['US']
48
- ```
49
-
50
- **This will conflict with any existing `Country` constant**
51
-
52
- To Use
53
-
54
- ```ruby
55
- gem 'countries', require: 'countries/global'
56
- ```
57
-
58
- ## Upgrading to 4.2 and 5.x
59
-
60
- Release 4.2.0 introduced changes to name attributes and finders and deprecated several methods to resolve some existing confusion regardign official ISO country names vs. the "common names" that are commonly used.
61
-
62
- The 5.0 release removed these deprecated methods and also removed support for Ruby 2.5 and 2.6
63
-
64
- Plase see [UPGRADE.md](../master/UPGRADE.md) for more information
65
-
66
- ## Attribute-Based Finder Methods
67
-
68
- You can lookup a country or an array of countries using any of the data attributes via the find\_country\_by_*attribute* dynamic methods:
69
-
70
- ```ruby
71
- c = ISO3166::Country.find_country_by_iso_short_name('italy')
72
- c = ISO3166::Country.find_country_by_any_name('united states')
73
- h = ISO3166::Country.find_all_by(:translated_names, 'França')
74
- list = ISO3166::Country.find_all_countries_by_region('Americas')
75
- c = ISO3166::Country.find_country_by_alpha2("FR")
76
- ```
77
-
78
- For a list of available attributes please see `ISO3166::DEFAULT_COUNTRY_HASH`.
79
- Note: searches are *case insensitive and ignore accents*.
80
-
81
- _Please note that `find_by_name`, `find_by_names`, `find_*_by_name` and `find_*_by_names` methods were removed in 5.0. See [UPGRADE.md](../master/UPGRADE.md) for more information_
82
-
83
- ## Country Info
84
-
85
- ### Identification Codes
86
-
87
- ```ruby
88
- c.number # => "840"
89
- c.alpha2 # => "US"
90
- c.alpha3 # => "USA"
91
- c.gec # => "US"
92
- ```
93
-
94
- ### Names & Translations
95
-
96
- ```ruby
97
- c.iso_long_name # => "The United States of America"
98
- c.iso_short_name # => "United States of America"
99
- c.common_name # => "United States" (This is a shortcut for c.translations('en'))
100
- c.unofficial_names # => ["United States of America", "Vereinigte Staaten von Amerika", "États-Unis", "Estados Unidos"]
101
-
102
- # Get the names for a country translated to its local languages
103
- c = Country[:BE]
104
- c.local_names # => ["België", "Belgique", "Belgien"]
105
- c.local_name # => "België"
106
-
107
- # Get a specific translation
108
- c.translation('de') # => 'Vereinigte Staaten von Amerika'
109
- c.translations['fr'] # => "États-Unis"
110
-
111
- # Get all translations for a locale, defaults to 'en'
112
- ISO3166::Country.translations # {"DE"=>"Germany",...}
113
- ISO3166::Country.translations('de') # {"DE"=>"Deutschland",...}
114
- ISO3166::Country.all_translated # ['Germany', ...]
115
- ISO3166::Country.all_translated('de') # ['Deutschland', ...]
116
-
117
- # Nationality
118
- c.nationality # => "American"
119
- ```
120
-
121
- ### Subdivisions & States
122
-
123
- ```ruby
124
- c.subdivisions # => {"CO" => {"name" => "Colorado", "names" => "Colorado"}, ... }
125
- c.subdivision_types # => ["state", "outlying_area", "district"]
126
- c.subdivisions_of_types(['state']) # => {"CO" => {"name" => "Colorado", "names" => "Colorado"}, ... }
127
- c.humanized_subdivision_types # => ["State", "Outlying area", "District"]
128
-
129
- # This is now deprecated. #states is an alias of #subdivisions and returns all subdivisions regardless of type
130
- c.states # => {"CO" => {"name" => "Colorado", "names" => "Colorado"}, ... }
131
-
132
-
133
- # Get specific translations for the country subdivisions
134
- c.subdivision_names_with_codes('es') #=> [ ..., ["Nuevo Hampshire", "NH"], ["Nueva Jersey", "NJ"], ... ]
135
-
136
- # Subdivision code with translations for all loaded locales
137
- c.subdivisions['NY'].code_with_translations #=> {"NY"=>{"en"=>"New York"}, ...}
138
- ```
139
-
140
- `#find_subdivision_by_name` Find a country's state using its code or name in any translation
141
-
142
- ```ruby
143
- > ISO3166::Country.new("IT").find_subdivision_by_name("Toscana").geo
144
- => {"latitude"=>43.771389, "longitude"=>11.254167, ... }
145
- > ISO3166::Country.new("IT").find_subdivision_by_name("Tuscany").geo
146
- => {"latitude"=>43.771389, "longitude"=>11.254167, ... }
147
- ```
148
-
149
- ### Location
150
-
151
- ```ruby
152
- c.latitude # => "37.09024"
153
- c.longitude # => "-95.712891"
154
-
155
- c.world_region # => "AMER"
156
- c.region # => "Americas"
157
- c.subregion # => "Northern America"
158
- ```
159
-
160
- Please note that `latitude_dec` and `longitude_dec` were deprecated on release 4.2 and removed in 5.0. These attributes have been redundant for several years, since the `latitude` and `longitude` fields have been switched decimal coordinates.
161
-
162
- ### Timezones **(optional)**
163
-
164
- Add `tzinfo` to your Gemfile and ensure it's required, Countries will not do this for you.
165
-
166
- ```ruby
167
- gem 'tzinfo', '~> 1.2', '>= 1.2.2'
168
- ```
169
-
170
- ```ruby
171
- c.timezones.zone_identifiers # => ["America/New_York", "America/Detroit", "America/Kentucky/Louisville", ...]
172
- c.timezones.zone_info # see [tzinfo docs](https://www.rubydoc.info/gems/tzinfo/TZInfo/CountryTimezone)
173
- c.timezones # see [tzinfo docs](https://www.rubydoc.info/gems/tzinfo/TZInfo/Country)
174
- ```
175
-
176
- ### Telephone Routing (E164)
177
-
178
- ```ruby
179
- c.country_code # => "1"
180
- c.national_destination_code_lengths # => 3
181
- c.national_number_lengths # => 10
182
- c.international_prefix # => "011"
183
- c.national_prefix # => "1"
184
- ```
185
-
186
- ### Boundary Boxes
187
-
188
- ```ruby
189
- c.min_longitude # => '45'
190
- c.min_latitude # => '22.166667'
191
- c.max_longitude # => '58'
192
- c.max_latitude # => '26.133333'
193
-
194
- c.bounds #> {"northeast"=>{"lat"=>22.166667, "lng"=>58}, "southwest"=>{"lat"=>26.133333, "lng"=>45}}
195
- ```
196
-
197
- ### European Union Membership
198
-
199
- ```ruby
200
- c.in_eu? # => false
201
- ```
202
-
203
- ### European Economic Area Membership
204
-
205
- ```ruby
206
- c.in_eea? # => false
207
- ```
208
-
209
- ### European Single Market Membership
210
-
211
- ```ruby
212
- c.in_esm? # => false
213
- ```
214
-
215
- ### EU VAT Area membership
216
-
217
- ```ruby
218
- c.in_eu_vat? # => false
219
- ```
220
-
221
- ### GDPR Compliant (European Economic Area Membership or UK)
222
-
223
- ```ruby
224
- c.gdpr_compliant? # => false
225
- ```
226
-
227
- ### Country Code in Emoji
228
-
229
- ```ruby
230
- c = Country['MY']
231
- c.emoji_flag # => "🇲🇾"
232
- ```
233
-
234
- ### Country Distance Unit (miles/kilometres)
235
-
236
- ```ruby
237
- c.distance_unit # => "MI"
238
- ```
239
-
240
- ### Plucking multiple attributes
241
-
242
- ```ruby
243
- ISO3166::Country.pluck(:alpha2, :iso_short_name) # => [["AD", "Andorra"], ["AE", "United Arab Emirates"], ...
244
- ```
245
-
246
- `.collect_countries_with` allows to collect various countries' informations using any valid method and query value:
247
- ```ruby
248
- > ISO3166::Country.collect_countries_with("VR",:subdivisions,:common_name)
249
- => ["Italy", "Monaco"]
250
- > ISO3166::Country.collect_countries_with("Caribbean",:subregion,:languages_spoken).flatten.uniq
251
- => ["en", "fr", "es", "ht", "nl"]
252
- > ISO3166::Country.collect_countries_with("Oceania",:region,:international_prefix).uniq
253
- => ["00", "011", "0011", "19", "05"]
254
- > ISO3166::Country.collect_countries_with("Antarctica",:continent,:emoji_flag)
255
- => ["🇦🇶", "🇬🇸", "🇧🇻", "🇹🇫", "🇭🇲"]
256
- > ISO3166::Country.collect_countries_with("🇸🇨",:emoji_flag,:common_name)
257
- => ["Seychelles"]
258
- ```
259
-
260
- `.collect_likely_countries_by_subdivision_name` allows to lookup all countries having the given state code or state name (in any translation)
261
-
262
- ```ruby
263
- ISO3166::Country.collect_likely_countries_by_subdivision_name("San José",:common_name)
264
- => ["Costa Rica", "Uruguay"]
265
- ```
266
-
267
-
268
- ## Currencies
269
-
270
- To enable currencies extension please add the following to countries initializer.
271
-
272
- ```ruby
273
- ISO3166.configuration.enable_currency_extension!
274
- ```
275
-
276
- Please note that it requires you to add "money" dependency to your gemfile.
277
-
278
- ```ruby
279
- gem "money", "~> 6.9"
280
- ```
281
-
282
- Countries now uses the [Money](https://github.com/RubyMoney/money) gem. What this means is you now get back a `Money::Currency` object that gives you access to all the currency information.
283
-
284
- ```ruby
285
- c = ISO3166::Country['us']
286
- c.currency.iso_code # => 'USD'
287
- c.currency.name # => 'United States Dollar'
288
- c.currency.symbol # => '$'
289
- ```
290
-
291
- ## Address Formatting
292
-
293
- A template for formatting addresses is available through the address_format method. These templates are compatible with the [Liquid](https://shopify.github.io/liquid/) template system.
294
-
295
- ```ruby
296
- c.address_format # => "{{recipient}}\n{{street}}\n{{city}} {{region}} {{postalcode}}\n{{country}}"
297
- ```
298
-
299
- ## Selective Loading of Locales
300
-
301
- As of 2.0 you can selectively load locales to reduce memory usage in production.
302
-
303
- By default we load `I18n.available_locales` if I18n is present, otherwise only `[:en]`. This means almost any Rails environment will only bring in its supported translations.
304
-
305
- You can add all the locales like this.
306
-
307
- ```ruby
308
- ISO3166.configure do |config|
309
- 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]
310
- end
311
- ```
312
-
313
- or something a bit more simple
314
- ```ruby
315
- ISO3166.configure do |config|
316
- config.locales = [:en, :de, :fr, :es]
317
- end
318
- ```
319
-
320
- If you change the value of `ISO3166.configuration.locales` after initialization, you should call `ISO3166::Data.reset` to reset the data cache, or you may end up with inconsistently loaded locales.
321
- As of 5.1.1, subdivision translations also respect this and will only load the selected locales.
322
-
323
- ## Loading Custom Data
324
-
325
- As of 2.0 countries supports loading custom countries / overriding data in its data set, though if you choose to do this please contribute back to the upstream repo!
326
-
327
- Any country registered this way will have its data available for searching etc... If you are overriding an existing country, for cultural reasons, our code uses a simple merge, not a deep merge so you will need to __bring in all data you wish to be available__. Bringing in an existing country will also remove it from the internal management of translations, __all registered countries will remain in memory__.
328
-
329
- ```ruby
330
- ISO3166::Data.register(
331
- alpha2: 'LOL',
332
- iso_short_name: 'Happy Country',
333
- translations: {
334
- 'en' => 'Happy Country',
335
- 'de' => 'glückliches Land'
336
- }
337
- )
338
-
339
- ISO3166::Country.new('LOL').iso_short_name == 'Happy Country'
340
- ```
341
-
342
- ## Mongoid
343
-
344
- Mongoid support has been added. It is required automatically if Mongoid is defined in your project.
345
-
346
- Use native country fields in your model:
347
-
348
- ```ruby
349
- field :country, type: Country
350
- ```
351
-
352
- Adds native support for searching/saving by a country object or alpha2 code.
353
-
354
- Searching:
355
-
356
- ```ruby
357
- # By alpha2
358
- spanish_things = Things.where(country: 'ES')
359
- spanish_things.first.country.iso_short_name # => "Spain"
360
-
361
- # By object
362
- spanish_things = Things.where(country: Country.find_by_iso_short_name('Spain')[1])
363
- spanish_things.first.country.iso_short_name # => "Spain"
364
- ```
365
-
366
- Saving:
367
-
368
- ```ruby
369
- # By alpha2
370
- spanish_things = Thing.new(country: 'ES')
371
- spanish_things.save!
372
- spanish_things.country.iso_short_name # => "Spain"
373
-
374
- # By object
375
- spanish_things = Thing.new(country: Country.find_by_iso_short_name('Spain')[1])
376
- spanish_things.save!
377
- spanish_things.country.iso_short_name # => "Spain"
378
- ```
379
-
380
- Note that the database stores only the alpha2 code and rebuilds the object when queried. To return the country name by default you can override the reader method in your model:
381
-
382
- ```ruby
383
- def country
384
- super.iso_short_name
385
- end
386
- ```
387
-
388
- ## Note on Patches/Pull Requests
389
-
390
- **Please do not submit pull requests on `cache/**/*`**. These files generated by a rake task when preparing new releases and are not meant to be manually updated.
391
-
392
- If you with to submit a PR to update or correct country data, please edit the corresponding YAML file `lib/countries/data/**`. Changes to the YAML files will be injected during the next `rake update_cache`.
393
-
394
- This project seeks to follow ISO3166, ISO4217 and E.164 standards in its data.
395
-
396
- This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
397
-
398
- ## Copyright
399
-
400
- Copyright (c) 2012-2015 hexorx \
401
- Copyright (c) 2015-2021 hexorx, rposborne \
402
- Copyright (c) 2022 hexorx, rposborne, pmor
403
-
404
- See LICENSE for details.
data/Rakefile DELETED
@@ -1,62 +0,0 @@
1
- #!/usr/bin/env rake
2
- # frozen_string_literal: true
3
-
4
- require 'bundler/gem_tasks'
5
-
6
- require 'rake'
7
- require 'rspec/core/rake_task'
8
- require 'yaml'
9
- require 'json'
10
-
11
- ISO3166_ROOT_PATH = File.dirname(__FILE__)
12
-
13
- Dir.glob('lib/countries/tasks/*.rake').each { |r| load r }
14
-
15
- desc 'Run all examples'
16
- RSpec::Core::RakeTask.new(:spec) do |t|
17
- t.rspec_opts = %w[--color --warnings]
18
- end
19
-
20
- task default: [:spec]
21
-
22
- desc 'Update CLDR subdivison data set'
23
- task :update_cldr_subdivison_data do
24
- require_relative './lib/countries/sources'
25
- Sources::CLDR::Downloader.subdivisions
26
- Sources::CLDR::SubdivisionUpdater.new.call
27
- end
28
-
29
- desc 'Update Cache'
30
- task :update_cache do
31
- codes = Dir['lib/countries/data/countries/*.yaml'].map { |x| File.basename(x, File.extname(x)) }.uniq.sort
32
- data = {}
33
-
34
- Dir['lib/countries/data/translations/countries-*.yaml'].each do |locale_file|
35
- locale = locale_file.split('-').last.split('.').first.downcase
36
- local_names = YAML.load_file(locale_file)
37
-
38
- out = File.join(File.dirname(__FILE__), 'lib', 'countries', 'cache', 'locales', "#{locale.gsub(/_/, '-')}.json")
39
- File.binwrite(out, local_names.to_json)
40
- end
41
-
42
- codes.each do |alpha2|
43
- country_file = File.join(File.dirname(__FILE__), 'lib', 'countries', 'data', 'countries', "#{alpha2}.yaml")
44
- data[alpha2] ||= YAML.load_file(country_file)[alpha2]
45
- end
46
-
47
- out_file = File.join(File.dirname(__FILE__), 'lib', 'countries', 'cache', 'countries.json')
48
- File.binwrite(out_file, data.to_json)
49
- end
50
-
51
- desc 'Sort subdivision YAML by code and translations by locale'
52
- task :cleanup_subdivision_yaml do
53
- ISO3166::Country.codes.each do |c_code|
54
- sd = Sources::Local::Subdivision.new(c_code)
55
- data = sd.load
56
- next if data.nil? || data == {}
57
-
58
- data = data.sort.to_h
59
- data['translations'] = data['translations'].sort.to_h unless data['translations'].nil?
60
- sd.save(data)
61
- end
62
- end
data/UPGRADE.md DELETED
@@ -1,39 +0,0 @@
1
- # Upgrading to 4.2 and 5.x
2
-
3
- In release 4.2 the `#name` attribute was deprecated in favour of `#iso_short_name` and we added the `#iso_long_name` attribute, to make it clear that these attributes use the ISO3166 names, and are not the "common names" most people might expect, eg: The ISO name for "United Kingdom" is "United Kingdom of Great Britain and Northern Ireland", but if you're building a dropdown box to select a country, you're likely expecting to see "United Kingdom" instead.
4
-
5
- "Common names" in English have been available in the translation data, via `#translation('en')`. As of release 4.2, a shortcut method has been added for simplicity, `#common_name`, which delegates to `#translation('en')`.
6
-
7
- For additional clarity, the `#names` method, which was an alias to `#unofficial_names` has also been deprecated, together with the finder methods that use `name` or `names` attributes.
8
-
9
- The `#name` and `#names` attributes, and corresponding finder methods were removed in 5.0.
10
-
11
- The replacement finders added in 5.0 are:
12
-
13
- - `#find_by_name` => `#find_by_any_name` - Searches all the name attributes, same as before
14
- - `#find_by_names` => `#find_by_unofficial_names`
15
- - `#find_*_by_name` => `#find_*_by_any_name`
16
- - `#find_*_by_names` => `#find_*_by_unofficial_names`
17
-
18
- With the addition of the new name attributes, there are now also the following finders:
19
-
20
- - `#find_by_common_name`/`#find_*_by_common_name`
21
- - `#find_by_iso_short_name`/`#find_*_by_iso_short_name`
22
- - `#find_by_iso_long_name`/`#find_*_by_iso_long_name`
23
-
24
- For translated country names, we use data originally sourced from [pkg-isocodes](https://salsa.debian.org/iso-codes-team/iso-codes), via the [i18n_data](https://github.com/grosser/i18n_data) gem, and these generally correspond to the expected "common names". Some corrections have been applied to these localized names. The methods to access translated names have not been changed.
25
-
26
- The 5.0 release removed support for Ruby 2.5 (EOL 2021-03-01) and 2.6 (EOL 2022-03-31)
27
-
28
- # Upgrading to 5.1
29
-
30
- In release 5.1 a `type` attribute was added to the subdivisions object, to allow filtering the collection of subdivisions.
31
-
32
- - `Country#subdivision_types` returns a list of subdivision types for that country (lowercase, snake_cased)
33
- - `#subdivisions_of_types(types)` accepts an array of subdivision types and returns the subdivisions for those types
34
-
35
- The `#states` method is deprecated to avoid confusion, as this method is an alias to `#subdivisions` and returns all subdivisions, regardless of type.
36
-
37
- To get a list of `state` subdivisions (something that was not possible before 5.1), use `subdivisions_of_types(['state'])`
38
-
39
- Please note that the subdivision types are obtained from ISO data, and each country defines its own subdivision types, eg: `state`, `district`, `region`, `municipality` and many others types exist.
data/bin/console DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'bundler/setup'
5
- require 'countries'
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require 'irb'
15
- IRB.start