worldwide 1.18.0 → 1.19.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 +3 -0
- data/Gemfile.lock +1 -1
- data/lib/worldwide/region.rb +25 -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: 38296da25beecf36a785ee19594e62e093eda9bf7b188851304644891600a4c7
|
4
|
+
data.tar.gz: 1d0d28aada01f52bfa3b439ffe1c54fd3bfd5af2bf2c78ea7e560f7858655319
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32586456f377f80533c8f4a79aec8b5e49a3abd841947d88459b908696d484690a9efe9b93e561b6b6ad45dff79c917aa26cf52423c5949aa2611fea539d139a
|
7
|
+
data.tar.gz: 927ffd197d06049ff64026bc4ac8daf175a2a30288aadfdc3366b2f311e5cbac3cb908882511a3cd59ece64e1d7b73957a93d3fb1500e13bae070ee503ba571f
|
data/CHANGELOG.md
CHANGED
@@ -29,6 +29,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
29
29
|
|
30
30
|
---
|
31
31
|
|
32
|
+
## [1.19.0] - 2025-10-15
|
33
|
+
- Add new method zip_type to determine if a postal code is `NUMERICAL`, `ALPHANUMERICAL`, or `NUMERICAL_WITH_PUNCTUATIONS`[#395](https://github.com/Shopify/worldwide/pull/395)
|
34
|
+
|
32
35
|
## [1.18.0] - 2025-10-08
|
33
36
|
- Fix broken CLDR data rake tasks [#389](https://github.com/Shopify/worldwide/pull/389)
|
34
37
|
- 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.
|
@@ -460,6 +467,24 @@ module Worldwide
|
|
460
467
|
end
|
461
468
|
end
|
462
469
|
|
470
|
+
# Returns the format type of the postal code.
|
471
|
+
# Analyzes the postal code example and regex pattern to determine if it contains
|
472
|
+
# only numbers, alphanumeric characters, or numbers with punctuation/spaces.
|
473
|
+
# Mainly used to determine the type of keyboard to show on mobile views.
|
474
|
+
#
|
475
|
+
# @return [String, nil] One of "ALPHANUMERIC", "NUMERIC", "NUMERIC_AND_PUNCTUATION", or nil if no zip_example
|
476
|
+
def zip_type
|
477
|
+
return nil if zip_example.nil?
|
478
|
+
|
479
|
+
if zip_example.match?(/[A-Za-z]/)
|
480
|
+
FORMAT_TYPES[:ALPHANUMERIC]
|
481
|
+
elsif zip_example.match?(/[[:punct:]\s]/) || zip_regex&.match?(/}-|\\-|-[?+*]|\(-/)
|
482
|
+
FORMAT_TYPES[:NUMERIC_AND_PUNCTUATION]
|
483
|
+
else
|
484
|
+
FORMAT_TYPES[:NUMERIC]
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
463
488
|
# Returns whether (and how firmly) we require a value in the zip field
|
464
489
|
# Possible returns:
|
465
490
|
# - "required" means a value must be supplied
|
data/lib/worldwide/version.rb
CHANGED