worldwide 0.6.1 → 0.6.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43a941ce0c45311eb558bbe78d3585613c38da718f2880533182d39ac8b1017b
4
- data.tar.gz: 8553b4c0e92338eeec626987ccbde3e28b3e8bd3b3f7eee82ae0c4315b519a23
3
+ metadata.gz: e612eada41704a41e5aa1b7dfce0cb4d94d81c9a8022c6392e45e57ee3f4aa62
4
+ data.tar.gz: 7ff48a7f2d370b615d07c8410f62bb1464ea64be2cbd8da7e7a17a443846f1bb
5
5
  SHA512:
6
- metadata.gz: 676b6e8903ef04b777c44ea464d7d77413a67f5b69993d4c3821252e554ee093ec07dde4f147684e2ad5cd57a8c5245beab11d116f19e74fd24fffba1ec4284d
7
- data.tar.gz: 15f67c2fdda70190a1742144577600f067b05e1f769785c582e7d44d858b8597b9263a3b604b1eed03ae6a0e0d3400afe6bdf67d47e836184645b95c178aa0ce
6
+ metadata.gz: 72e2d6a9985fe09d8ed9fa5179e1525e56cd24c2603e8f4317f0ce6fe15a0cc1692738042defdc8be28fa3667e54b65b8a0e58995660e025fcfeefe4850f3bfb
7
+ data.tar.gz: e4696a9bec42809f27a803a1d39a8413eec5656666133602644faeb292fb9a0fcebf1fc64c6fd9cf8f9bd84d9b2073f34120cfcc98d6c3631b71f13d6a60fef9
data/CHANGELOG.md CHANGED
@@ -31,6 +31,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
31
31
 
32
32
  ---
33
33
 
34
+ [0.6.3] - 2023-12-11
35
+
36
+ - Change HM, TF and GS `group_name` to respective continents based on M49. [#60](https://github.com/Shopify/worldwide/pull/60)
37
+
38
+ [0.6.2] - 2023-12-11
39
+
40
+ - Zone lookup by Hash [#61](https://github.com/Shopify/worldwide/pull/61)
41
+
34
42
  [0.6.1] - 2023-12-11
35
43
 
36
44
  - Allow building number in address2 for DK [#53](https://github.com/Shopify/worldwide/pull/53)
data/Gemfile.lock CHANGED
@@ -13,7 +13,7 @@ GIT
13
13
  PATH
14
14
  remote: .
15
15
  specs:
16
- worldwide (0.6.1)
16
+ worldwide (0.6.3)
17
17
  activesupport (~> 7.0)
18
18
  i18n (~> 1.12.0)
19
19
  phonelib (~> 0.8)
@@ -1,8 +1,8 @@
1
1
  ---
2
2
  tax: 0.0
3
3
  name: South Georgia And The South Sandwich Islands
4
- group: Other Countries
5
- group_name: Other
4
+ group: South American Countries
5
+ group_name: South America
6
6
  code: GS
7
7
  unit_system: metric
8
8
  currency: GBP
@@ -1,8 +1,8 @@
1
1
  ---
2
2
  tax: 0.0
3
3
  name: Heard Island And Mcdonald Islands
4
- group: Other Countries
5
- group_name: Other
4
+ group: Oceanian Countries
5
+ group_name: Oceania
6
6
  code: HM
7
7
  inhabited: false
8
8
  unit_system: metric
@@ -1,8 +1,8 @@
1
1
  ---
2
2
  tax: 0.0
3
3
  name: French Southern Territories
4
- group: Other Countries
5
- group_name: Other
4
+ group: African Countries
5
+ group_name: Africa
6
6
  code: TF
7
7
  code_alternates:
8
8
  - FR-TF
@@ -249,6 +249,7 @@ module Worldwide
249
249
 
250
250
  @parents = [].to_set
251
251
  @zones = []
252
+ @zones_by_code = {}
252
253
  end
253
254
 
254
255
  def inspect
@@ -262,6 +263,7 @@ module Worldwide
262
263
 
263
264
  region.parents << self
264
265
  @zones.append(region)
266
+ add_zone_to_hash(region)
265
267
  end
266
268
 
267
269
  # Attributes
@@ -320,6 +322,7 @@ module Worldwide
320
322
  # A user-facing name in the currently-active locale's language.
321
323
  def full_name(locale: I18n.locale)
322
324
  lookup_code = cldr_code
325
+
323
326
  if /^[0-9]+$/.match?(lookup_code) || lookup_code.length < 3
324
327
  Worldwide::Cldr.t("territories.#{lookup_code}", locale: locale, default: legacy_name)
325
328
  else
@@ -358,17 +361,14 @@ module Worldwide
358
361
  if Worldwide::Util.present?(code)
359
362
  search_code = code.to_s.upcase
360
363
  alt_search_code = "#{search_code[0..1]}-#{search_code[2..-1]}"
364
+ zone = nil
361
365
 
362
- zones.find do |region|
363
- [search_code, alt_search_code].any? do |candidate|
364
- candidate == subdivision_code(region.iso_code) ||
365
- candidate == region.alpha_three ||
366
- candidate == region.iso_code ||
367
- candidate == region.legacy_code ||
368
- candidate == region.numeric_three ||
369
- region&.code_alternates&.any?(candidate)
370
- end
366
+ [search_code, alt_search_code].each do |candidate|
367
+ zone = @zones_by_code[candidate]
368
+ break if zone
371
369
  end
370
+
371
+ return zone unless zone.nil?
372
372
  elsif Worldwide::Util.present?(name)
373
373
  search_name = name.upcase
374
374
 
@@ -414,6 +414,17 @@ module Worldwide
414
414
 
415
415
  private
416
416
 
417
+ def add_zone_to_hash(zone)
418
+ @zones_by_code[subdivision_code(zone.iso_code)] = zone if Util.present?(subdivision_code(zone.iso_code))
419
+ @zones_by_code[zone.alpha_three] = zone if Util.present?(zone.alpha_three)
420
+ @zones_by_code[zone.iso_code] = zone if Util.present?(zone.iso_code)
421
+ @zones_by_code[zone.legacy_code] = zone if Util.present?(zone.legacy_code)
422
+ @zones_by_code[zone.numeric_three] = zone if Util.present?(zone.numeric_three)
423
+ zone.code_alternates&.each do |code|
424
+ @zones_by_code[code] = zone
425
+ end
426
+ end
427
+
417
428
  def answers_to_cldr_code(search_code)
418
429
  return false if Util.blank?(search_code) || Util.blank?(cldr_code)
419
430
  return true if search_code.casecmp(cldr_code).zero?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Worldwide
4
- VERSION = "0.6.1"
4
+ VERSION = "0.6.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worldwide
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify