worldwide 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43a941ce0c45311eb558bbe78d3585613c38da718f2880533182d39ac8b1017b
4
- data.tar.gz: 8553b4c0e92338eeec626987ccbde3e28b3e8bd3b3f7eee82ae0c4315b519a23
3
+ metadata.gz: 378551ef286d7b7f398ee9ca149e417ac0f85efbba591a97fa8373de299258fd
4
+ data.tar.gz: 2a26ebd6f73862b5cc01bdae65ed710dbb7af5666a65f11d224bb529acb32d15
5
5
  SHA512:
6
- metadata.gz: 676b6e8903ef04b777c44ea464d7d77413a67f5b69993d4c3821252e554ee093ec07dde4f147684e2ad5cd57a8c5245beab11d116f19e74fd24fffba1ec4284d
7
- data.tar.gz: 15f67c2fdda70190a1742144577600f067b05e1f769785c582e7d44d858b8597b9263a3b604b1eed03ae6a0e0d3400afe6bdf67d47e836184645b95c178aa0ce
6
+ metadata.gz: 6487ee321f130d34da0da8f58bf0bcc38815eecbec6f502358204a859b22c31afc6e9bfe3d8ee002b4e57e3b50040aca9fda443fc05889d62165755c706b449f
7
+ data.tar.gz: 1caf34f3c88a07fb3aa532f8192caf1a448af2795b710369645c1841cad6de722fe525833fff4b25a0c992fdb853e6fadf2ffc4244ee4aec0ee6073953147744
data/CHANGELOG.md CHANGED
@@ -27,10 +27,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
27
27
 
28
28
  ## [Unreleased]
29
29
 
30
- - nil
30
+ - nil.
31
31
 
32
32
  ---
33
33
 
34
+ [0.6.2] - 2023-12-11
35
+
36
+ - Zone lookup by Hash [#61](https://github.com/Shopify/worldwide/pull/61)
37
+
34
38
  [0.6.1] - 2023-12-11
35
39
 
36
40
  - 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.2)
17
17
  activesupport (~> 7.0)
18
18
  i18n (~> 1.12.0)
19
19
  phonelib (~> 0.8)
@@ -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.2"
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify