countries 4.2.0 β†’ 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,6 +24,19 @@ module ISO3166
24
24
  @loaded_locales = []
25
25
  end
26
26
 
27
+ # Enables the integration with the {Money}[https://github.com/RubyMoney/money] gem
28
+ #
29
+ # Please note that it requires you to add "money" gem to your gemfile.
30
+ #
31
+ # gem "money", "~> 6.9"
32
+ #
33
+ # *WARNING* if you have a top level class named +Money+ you will conflict with this gem.
34
+ #
35
+ # @example
36
+ # c = ISO3166::Country['us']
37
+ # c.currency.iso_code # => 'USD'
38
+ # c.currency.name # => 'United States Dollar'
39
+ # c.currency.symbol # => '$'
27
40
  def enable_currency_extension!
28
41
  require 'countries/country/currency_methods'
29
42
  ISO3166::Country.prepend(ISO3166::CountryCurrencyMethods)
@@ -1,8 +1,11 @@
1
1
  require 'money'
2
2
 
3
3
  module ISO3166
4
- # Optional extension which allows you to get back a Money::Currency object with all the currency info
4
+ # Optional extension which allows you to get back a +Money::Currency+ object with all the currency info.
5
+ # This requires enabling the integration with the {Money}[https://github.com/RubyMoney/money] gem (See {ISO3166::Configuration#enable_currency_extension!})
5
6
  module CountryCurrencyMethods
7
+
8
+ # @return [Money::Currency] The currency data for this Country's +currency_code+
6
9
  def currency
7
10
  Money::Currency.find(data['currency_code'])
8
11
  end
@@ -32,6 +32,9 @@ module ISO3166
32
32
  'z' => 'πŸ‡Ώ'
33
33
  }.freeze
34
34
 
35
+ # @return [String] the emoji flag for this country
36
+ #
37
+ # The emoji flag for this country, using Unicode Regional Indicator characters. e.g: "U+1F1FA U+1F1F8" for πŸ‡ΊπŸ‡Έ
35
38
  def emoji_flag
36
39
  alpha2.downcase.chars.map { |c| CODE_POINTS[c] }.join('')
37
40
  end
@@ -65,14 +65,12 @@ module ISO3166
65
65
  to_s <=> other.to_s
66
66
  end
67
67
 
68
- def start_of_week
69
- data['start_of_week']
70
- end
71
-
68
+ # +true+ if this Country has any Subdivisions.
72
69
  def subdivisions?
73
70
  !subdivisions.empty?
74
71
  end
75
72
 
73
+ # @return [Array<ISO3166::Subdivision>] the list of subdivisions for this Country.
76
74
  def subdivisions
77
75
  @subdivisions ||= if data['subdivisions']
78
76
  self.class.create_subdivisions(data['subdivisions'])
@@ -81,20 +79,25 @@ module ISO3166
81
79
  end
82
80
  end
83
81
 
82
+ # @param locale [String] The locale to use for translations.
83
+ # @return [Array<Array>] This Country's subdivision pairs of names and codes.
84
84
  def subdivision_names_with_codes(locale = 'en')
85
85
  subdivisions.map { |k, v| [v.translations[locale] || v.name, k] }
86
86
  end
87
87
 
88
88
  alias states subdivisions
89
89
 
90
+ # +true+ if this country is a member of the European Union.
90
91
  def in_eu?
91
92
  data['eu_member'].nil? ? false : data['eu_member']
92
93
  end
93
94
 
95
+ # +true+ if this country is a member of the European Economic Area.
94
96
  def in_eea?
95
97
  data['eea_member'].nil? ? false : data['eea_member']
96
98
  end
97
99
 
100
+ # +true+ if this country is a member of the European Single Market.
98
101
  def in_esm?
99
102
  data['esm_member'].nil? ? in_eea? : data['esm_member']
100
103
  end
@@ -103,20 +106,24 @@ module ISO3166
103
106
  data['iso_short_name']
104
107
  end
105
108
 
109
+ # @return [Array<String>] the list of names for this Country in all loaded locales.
106
110
  def translated_names
107
111
  data['translations'].values
108
112
  end
109
113
 
114
+ # @param locale [String] The locale to use for translations.
115
+ # @return [String] the name of this Country in the selected locale.
110
116
  def translation(locale = 'en')
111
117
  data['translations'][locale.to_s.downcase]
112
118
  end
113
119
 
120
+ # @return [String] the β€œcommon name” of this Country in English.
114
121
  def common_name
115
122
  ISO3166.configuration.locales = ISO3166.configuration.locales.append(:en).uniq
116
123
  translation('en')
117
124
  end
118
125
 
119
- # TODO: Looping through locale langs could be be very slow across multiple countries
126
+ # @return [Array<String>] TThe list of names for this Country, in this Country's locales.
120
127
  def local_names
121
128
  ISO3166.configuration.locales = (ISO3166.configuration.locales + languages.map(&:to_sym)).uniq
122
129
  reload
@@ -124,10 +131,13 @@ module ISO3166
124
131
  @local_names ||= languages.map { |language| translations[language] }
125
132
  end
126
133
 
134
+ # @return [String] The name for this Country, in this Country's locale.
127
135
  def local_name
128
136
  @local_name ||= local_names.first
129
137
  end
130
138
 
139
+ # @return [String] This Country's ISO Short Name
140
+ # @deprecated Use {#iso_short_name} instead.
131
141
  def name
132
142
  if RUBY_VERSION =~ /^3\.\d\.\d/
133
143
  warn "DEPRECATION WARNING: The Country#name method has been deprecated. Please use Country#iso_short_name instead or refer to the README file for more information on this change.", uplevel: 1, category: :deprecated
@@ -137,6 +147,8 @@ module ISO3166
137
147
  iso_short_name
138
148
  end
139
149
 
150
+ # @return [Array<String>] Array of unofficial, slang names or aliases for this Country
151
+ # @deprecated Use {#unofficial_names} instead.
140
152
  def names
141
153
  if RUBY_VERSION =~ /^3\.\d\.\d/
142
154
  warn "DEPRECATION WARNING: The Country#names method has been deprecated. Please use Country#unofficial_names instead or refer to the README file for more information on this change.", uplevel: 1, category: :deprecated
@@ -146,6 +158,94 @@ module ISO3166
146
158
  unofficial_names
147
159
  end
148
160
 
161
+ # @!attribute alpha2
162
+ # @return [String] the ISO3166 alpha-2 code for this Country
163
+ #
164
+ # @!attribute alpha3
165
+ # @return [String] the ISO3166 alpha-3 code for this Country
166
+ #
167
+ # @!attribute address_format
168
+ # @return [String] a template for formatting addresses in this Country.
169
+ #
170
+ # @!attribute continent
171
+ # @return [String] the continent for this Country
172
+ #
173
+ # @!attribute country_code
174
+ # @return [String] the country calling code for this Country
175
+ #
176
+ # @!attribute currency_code
177
+ # @return [String] the ISO 4217 currency code for this Country
178
+ #
179
+ # @!attribute gec
180
+ # @return [String] the "Geopolitical Entities and Codes", formerly FIPS 10-4 code for this Country
181
+ #
182
+ # @!attribute geo
183
+ # @return [Hash] the hash of coordinates for this Country.
184
+ #
185
+ # @!attribute international_prefix
186
+ # @return [String] the phone prefix used in this Country for dialing international numbers
187
+ #
188
+ # @!attribute ioc
189
+ # @return [String] The International Olympic Committee code for for this Country
190
+ #
191
+ # @!attribute national_destination_code_lengths
192
+ # @return [Array<Integer>] Lengths of phone number destination codes
193
+ #
194
+ # @!attribute national_number_lengths
195
+ # @return [Array<Integer>] Lengths of phone numbers
196
+ #
197
+ # @!attribute national_prefix
198
+ # @return [String] the phone prefix used in this Country for dialing national numbers
199
+ #
200
+ # @!attribute nanp_prefix
201
+ # @return [String] the NANP prefix code
202
+ #
203
+ # @!attribute nationality
204
+ # @return [String] the nationality for this Country, in English
205
+ #
206
+ # @!attribute number
207
+ # @return [String] The ISO 3166-1 numeric code for this Country
208
+ #
209
+ # @!attribute languages_official
210
+ # @return [Array<String>] the list of official languages (locale codes) for this Country
211
+ #
212
+ # @!attribute languages_spoken
213
+ # @return [Array<String>] the list of spoken languages (locale codes) for this Country
214
+ #
215
+ # @!attribute translations
216
+ # @return [Hash] The hash of country name translations for this Country.
217
+ #
218
+ # @!attribute postal_code
219
+ # @return [Boolean] Does this Country uses postal codes in addresses
220
+ #
221
+ # @!attribute postal_code_format
222
+ # @return [String] The regex for valid postal codes in this Country
223
+ #
224
+ # @!attribute region
225
+ # @return [String] The Region this country is in. Approximately matches the United Nations geoscheme
226
+ #
227
+ # @!attribute unofficial_names
228
+ # @return [Array<String>] Array of unofficial, slang names or aliases for this Country
229
+ #
230
+ # @!attribute start_of_week
231
+ # @return [String] The starting day of the week ( +'monday'+ or +'sunday'+ )
232
+ #
233
+ # @!attribute subregion
234
+ # @return [String] The Subegion this country is in. Approximately matches the United Nations geoscheme's Subregions
235
+ #
236
+ # @!attribute un_locode
237
+ # @return [String] The UN/LOCODE prefix for this Country
238
+ #
239
+ # @!attribute vat_rates
240
+ # @return [Hash] the hash of VAT Rates for this Country
241
+ #
242
+ # @!attribute world_region
243
+ # @return [String] The "World Region" this country is in: +"AMER"+ , +"APAC"+ or +"EMEA"+
244
+
245
+
246
+
247
+ private
248
+
149
249
  def reload
150
250
  @data = if @country_data_or_code.is_a?(Hash)
151
251
  @country_data_or_code
@@ -55,8 +55,6 @@ IL:
55
55
  reduced: []
56
56
  super_reduced:
57
57
  parking:
58
- postal_code: true
59
- postal_code_format: "\\d{5}(?:\\d{2})?"
60
58
  unofficial_names:
61
59
  - Israel
62
60
  - IsraΓ«l
@@ -36,7 +36,7 @@ KH:
36
36
  nationality: Cambodian
37
37
  number: '116'
38
38
  postal_code: true
39
- postal_code_format: "\\d{5}"
39
+ postal_code_format: "\\d{5,6}"
40
40
  region: Asia
41
41
  start_of_week: monday
42
42
  subregion: South-Eastern Asia
@@ -42,7 +42,7 @@ TW:
42
42
  nationality: Taiwanese
43
43
  number: '158'
44
44
  postal_code: true
45
- postal_code_format: "\\d{3}(?:\\d{2})?"
45
+ postal_code_format: "\\d{3}(?:\\d{2,3})?"
46
46
  region: Asia
47
47
  start_of_week: monday
48
48
  subregion: Eastern Asia
@@ -1,5 +1,4 @@
1
1
  module ISO3166
2
- ##
3
2
  # Handles building the in memory store of countries data
4
3
  class Data
5
4
  @@cache_dir = [File.dirname(__FILE__), 'cache']
@@ -24,6 +23,9 @@ module ISO3166
24
23
  @@cache_dir = value
25
24
  end
26
25
 
26
+ # Registers a new Country with custom data.
27
+ # 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
+ # Overriding an existing country will also remove it from the internal management of translations.
27
29
  def register(data)
28
30
  alpha2 = data[:alpha2].upcase
29
31
  @@registered_data[alpha2] = deep_stringify_keys(data)
@@ -32,6 +34,7 @@ module ISO3166
32
34
  @@cache = cache.merge(@@registered_data)
33
35
  end
34
36
 
37
+ # Removes a country from the loaded data
35
38
  def unregister(alpha2)
36
39
  alpha2 = alpha2.to_s.upcase
37
40
  @@cache.delete(alpha2)
@@ -42,6 +45,7 @@ module ISO3166
42
45
  update_cache
43
46
  end
44
47
 
48
+ # Resets the loaded data and cache
45
49
  def reset
46
50
  @@cache = {}
47
51
  @@registered_data = {}
@@ -1,5 +1,17 @@
1
1
  require 'countries'
2
2
 
3
+ # Some apps might not want to constantly call +ISO3166::Country+. This gem has a helper that can provide a Country class
4
+ #
5
+ # With global Country Helper enabled
6
+ #
7
+ # c = Country['US']
8
+ #
9
+ # This will conflict with any existing Country constant
10
+ #
11
+ # To Use
12
+ #
13
+ # gem 'countries', require: 'countries/global'
14
+ #
3
15
  class Country < ISO3166::Country
4
16
 
5
17
  end
@@ -5,6 +5,7 @@ module ISO3166
5
5
  end
6
6
 
7
7
  class << self
8
+ # Convert an +ISO3166::Country+ to the data that is stored by Mongoid.
8
9
  def mongoize(country)
9
10
  if country.is_a?(self) && !country.data.nil?
10
11
  country.alpha2
@@ -13,10 +14,12 @@ module ISO3166
13
14
  end
14
15
  end
15
16
 
17
+ # Get the object as it was stored with Mongoid, and instantiate an +ISO3166::Country+.
16
18
  def demongoize(alpha2)
17
19
  new(alpha2)
18
20
  end
19
21
 
22
+ # Convert an +ISO3166::Country+ to the data that is stored by Mongoid.
20
23
  def evolve(country)
21
24
  mongoize(country)
22
25
  end
@@ -4,8 +4,11 @@ require 'nokogiri'
4
4
  require 'fileutils'
5
5
  require 'json'
6
6
 
7
+ # Support code to allow updating subdivision data from the Unicode CLDR repository
7
8
  module Sources
9
+ # Support code to allow updating subdivision data from the Unicode CLDR repository
8
10
  module CLDR
11
+ # Downloads data from the Unicode CLDR repository
9
12
  module Downloader
10
13
  module_function
11
14
 
@@ -1,5 +1,6 @@
1
1
  module Sources
2
2
  module CLDR
3
+ # Auxiliary Subdivision class to support loading Unicode CLDR data to update local files
3
4
  class Subdivision
4
5
  attr_reader :xml, :language_code
5
6
  def initialize(language_code:, xml:)
@@ -5,6 +5,7 @@ require 'pry'
5
5
 
6
6
  module Sources
7
7
  module CLDR
8
+ # Updates local subdivision files with data from the Unicode CLDR repository
8
9
  class SubdivisionUpdater
9
10
  def call
10
11
  d = Dir['./tmp/cldr/trunk/common/subdivisions/*.xml']
@@ -1,5 +1,7 @@
1
1
  module Sources
2
+ # Support code to allow updating subdivision data from the Unicode CLDR repository
2
3
  module Local
4
+ # Loader for locally-cached data, to allow merging Unicode CLDR data with existing local data
3
5
  class CachedLoader
4
6
  attr_reader :klass
5
7
  def initialize(klass)
@@ -1,5 +1,6 @@
1
1
  module Sources
2
2
  module Local
3
+ # Auxiliary Subdivision class to support loading the local subdivision data to be updated with Unicode CLDR data
3
4
  class Subdivision
4
5
  attr_reader :code
5
6
  def initialize(code)
@@ -1,6 +1,8 @@
1
- # Extend Country class with support for timezones
2
1
  module ISO3166
3
- # Extend Country class with support for timezones
2
+ # Extend Country class with support for timezones. Requires the {tzinfo}[https://github.com/tzinfo/tzinfo] gem
3
+ #
4
+ # gem 'tzinfo'
5
+ #
4
6
  module TimezoneExtensions
5
7
  def timezones
6
8
  @tz_country ||= TZInfo::Country.get(alpha2)
@@ -1,9 +1,8 @@
1
1
  module ISO3166
2
2
  # Extend the hash class to allow locale lookup fall back behavior
3
3
  #
4
- # ex:
5
- # if a country has translations for pt, and the user looks up `pt-br` fallback
6
- # to `pt` to prevent from showing nil values
4
+ # E.g. if a country has translations for +pt+, and the user looks up +pt-br+ fallback
5
+ # to +pt+ to prevent from showing nil values
7
6
  class Translations < Hash
8
7
  def [](locale)
9
8
  super(locale) || super(locale.to_s.sub(/-.*/, ''))
@@ -1,3 +1,3 @@
1
1
  module Countries
2
- VERSION = '4.2.0'.freeze
2
+ VERSION = '4.2.1'.freeze
3
3
  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: 4.2.0
4
+ version: 4.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Robinson