worldwide 1.18.0 → 1.20.0
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/lib/worldwide/region.rb +30 -0
- 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: 1cbb9e0606b63675d9a783759723f4083661820aae022057574e8abaf4490963
|
|
4
|
+
data.tar.gz: d94f426622537b52d93c10a0f9be29980ad131915788ba77224d6043f5583284
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 66cc5d0a9561244ae777703aac0acf90a702cb0f891f88d93e8bdf4c5cf72c000c5ee7c107d348dd90dd2531078f505433ad260c97407c3e4fe63df87840f709
|
|
7
|
+
data.tar.gz: 208de89a7c70089590460ab0675ff1e212752a6f1297dc57a0403ede1605803d31d8b52c5a1081ecaa604b00fe3abe00379396ade030436a46168145c49501a9
|
data/CHANGELOG.md
CHANGED
|
@@ -29,6 +29,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
|
29
29
|
|
|
30
30
|
---
|
|
31
31
|
|
|
32
|
+
## [1.20.0] - 2025-10-15
|
|
33
|
+
- Add has_provinces? method to Region [#396](https://github.com/Shopify/worldwide/pull/396)
|
|
34
|
+
|
|
35
|
+
## [1.19.0] - 2025-10-15
|
|
36
|
+
- Add new method zip_type to determine if a postal code is `NUMERIC`, `ALPHANUMERIC`, or `NUMERIC_AND_PUNCTUATION`[#395](https://github.com/Shopify/worldwide/pull/395)
|
|
37
|
+
|
|
32
38
|
## [1.18.0] - 2025-10-08
|
|
33
39
|
- Fix broken CLDR data rake tasks [#389](https://github.com/Shopify/worldwide/pull/389)
|
|
34
40
|
- Read paths files in `configure_i18n` instead of at module initialization (ibid.)
|
data/Gemfile.lock
CHANGED
data/lib/worldwide/region.rb
CHANGED
|
@@ -9,6 +9,13 @@ module Worldwide
|
|
|
9
9
|
RECOMMENDED = "recommended"
|
|
10
10
|
OPTIONAL = "optional"
|
|
11
11
|
|
|
12
|
+
# Accpetable format types of the postal code.
|
|
13
|
+
FORMAT_TYPES = {
|
|
14
|
+
ALPHANUMERIC: "ALPHANUMERIC",
|
|
15
|
+
NUMERIC: "NUMERIC",
|
|
16
|
+
NUMERIC_AND_PUNCTUATION: "NUMERIC_AND_PUNCTUATION",
|
|
17
|
+
}
|
|
18
|
+
|
|
12
19
|
# The default `.inspect` isn't a good fit for Region, because it can end up dumping a lot of info
|
|
13
20
|
# as it walks the hierarchy of descendants. So, instead, we provide our own `.inspect` that
|
|
14
21
|
# only shows a restricted subset of the object's fields.
|
|
@@ -394,6 +401,11 @@ module Worldwide
|
|
|
394
401
|
!!format["show"]&.include?("{city}")
|
|
395
402
|
end
|
|
396
403
|
|
|
404
|
+
# Does this region have provinces in their addresses?
|
|
405
|
+
def has_provinces?
|
|
406
|
+
!!format["show"]&.include?("{province}")
|
|
407
|
+
end
|
|
408
|
+
|
|
397
409
|
# Is this Region considered a "province" (political subdivision of a "country")?
|
|
398
410
|
def province?
|
|
399
411
|
@province
|
|
@@ -460,6 +472,24 @@ module Worldwide
|
|
|
460
472
|
end
|
|
461
473
|
end
|
|
462
474
|
|
|
475
|
+
# Returns the format type of the postal code.
|
|
476
|
+
# Analyzes the postal code example and regex pattern to determine if it contains
|
|
477
|
+
# only numbers, alphanumeric characters, or numbers with punctuation/spaces.
|
|
478
|
+
# Mainly used to determine the type of keyboard to show on mobile views.
|
|
479
|
+
#
|
|
480
|
+
# @return [String, nil] One of "ALPHANUMERIC", "NUMERIC", "NUMERIC_AND_PUNCTUATION", or nil if no zip_example
|
|
481
|
+
def zip_type
|
|
482
|
+
return nil if zip_example.nil?
|
|
483
|
+
|
|
484
|
+
if zip_example.match?(/[A-Za-z]/)
|
|
485
|
+
FORMAT_TYPES[:ALPHANUMERIC]
|
|
486
|
+
elsif zip_example.match?(/[[:punct:]\s]/) || zip_regex&.match?(/}-|\\-|-[?+*]|\(-/)
|
|
487
|
+
FORMAT_TYPES[:NUMERIC_AND_PUNCTUATION]
|
|
488
|
+
else
|
|
489
|
+
FORMAT_TYPES[:NUMERIC]
|
|
490
|
+
end
|
|
491
|
+
end
|
|
492
|
+
|
|
463
493
|
# Returns whether (and how firmly) we require a value in the zip field
|
|
464
494
|
# Possible returns:
|
|
465
495
|
# - "required" means a value must be supplied
|
data/lib/worldwide/version.rb
CHANGED