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 +4 -4
- data/CHANGELOG.md +5 -1
- data/Gemfile.lock +1 -1
- data/lib/worldwide/region.rb +20 -9
- data/lib/worldwide/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 378551ef286d7b7f398ee9ca149e417ac0f85efbba591a97fa8373de299258fd
|
4
|
+
data.tar.gz: 2a26ebd6f73862b5cc01bdae65ed710dbb7af5666a65f11d224bb529acb32d15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/lib/worldwide/region.rb
CHANGED
@@ -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
|
-
|
363
|
-
|
364
|
-
|
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?
|
data/lib/worldwide/version.rb
CHANGED