worldwide 0.1.1 → 0.2.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 +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/worldwide/region.rb +16 -4
- data/lib/worldwide/regions_loader.rb +5 -0
- data/lib/worldwide/version.rb +1 -1
- data/worldwide.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c3c323e57e56b609ebdc7fe5d7965a2d5348fede9b72110627528529b3b7ab5
|
4
|
+
data.tar.gz: f4007e0986bc9702af7d95f3c352a11937292d9f6fbbd8c21e8a1a635fcc7993
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 333628df88179b5d2696634f3dadec1a548a5a2ef4baebcac86832077565f5f826036da107cdf8d5d4ed84323563235265df4b0bf37648f7d7691ef120e81216
|
7
|
+
data.tar.gz: cdbad17228b52fc39d188fdbf2e13800aa4015caf18cd314d9cdfcd7f3a7b63f585c2cbd69eec36bb8c450dae83e649c35a0c661c651e55293c626582e03a785
|
data/CHANGELOG.md
CHANGED
@@ -28,6 +28,14 @@ Nil.
|
|
28
28
|
|
29
29
|
---
|
30
30
|
|
31
|
+
[0.2.0] - 2023-11-01
|
32
|
+
|
33
|
+
- Add Region#group and Region#group_name [#15](https://github.com/Shopify/worldwide/pull/15)
|
34
|
+
- Ensure Region#has_zip? returns a boolean for all regions [#17](https://github.com/Shopify/worldwide/pull/17)
|
35
|
+
- Zip normalization bugfix when parent isocode is not set [#6](https://github.com/Shopify/worldwide/pull/6)
|
36
|
+
- Update region parent when alternates are defined [#18](https://github.com/Shopify/worldwide/pull/18)
|
37
|
+
- Add partial matching for Region#valid_zip? [#19](https://github.com/Shopify/worldwide/pull/19)
|
38
|
+
|
31
39
|
[0.1.1] - 2023-10-27
|
32
40
|
|
33
41
|
- Fix issue with deploy to rubygems.org failing
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -99,7 +99,7 @@ Worldwide exposes the notion of a "region", or political subdivision. This can
|
|
99
99
|
|
100
100
|
Note that, when exposing geographic information to users, you should be careful what you refer
|
101
101
|
to as a "country". For backward compatibility with historical APIs, we use the term "country"
|
102
|
-
to refer to what CLDR refers to as a "territory", and what we describe in our user
|
102
|
+
to refer to what CLDR refers to as a "territory", and what we describe in our user interface as
|
103
103
|
a "country / region". Examples of such entities include Canada, the United States, and Russia,
|
104
104
|
but also territories with a "dual" status such as Guernsey, Hong Kong, and Martinique.
|
105
105
|
|
data/lib/worldwide/region.rb
CHANGED
@@ -19,6 +19,8 @@ module Worldwide
|
|
19
19
|
:example_city,
|
20
20
|
:flag,
|
21
21
|
:format,
|
22
|
+
:group,
|
23
|
+
:group_name,
|
22
24
|
:cldr_code,
|
23
25
|
:iso_code,
|
24
26
|
:languages,
|
@@ -65,6 +67,14 @@ module Worldwide
|
|
65
67
|
# - show: how to arrange the fields when formatting an address for display
|
66
68
|
attr_accessor :format
|
67
69
|
|
70
|
+
# The string that results from appending " Countries" to the adjectival form of the {group_name}
|
71
|
+
# @example
|
72
|
+
# CountryDb.country(code: "CA").group == "North American Countries"
|
73
|
+
attr_accessor :group
|
74
|
+
|
75
|
+
# The continent that this region is part of.
|
76
|
+
attr_accessor :group_name
|
77
|
+
|
68
78
|
# If this flag is set, then we support provinces "under the hood" for this country, but we do not
|
69
79
|
# show them as part of a formatted address. If the province is missing, we will auto-infer it
|
70
80
|
# based on the zip (note that this auto-inference may be wrong for some addresses near a border).
|
@@ -210,6 +220,8 @@ module Worldwide
|
|
210
220
|
@currency = nil
|
211
221
|
@flag = nil
|
212
222
|
@format = {}
|
223
|
+
@group = nil
|
224
|
+
@group_name = nil
|
213
225
|
@languages = []
|
214
226
|
@neighbours = []
|
215
227
|
@partial_zip_regex = nil
|
@@ -289,7 +301,7 @@ module Worldwide
|
|
289
301
|
|
290
302
|
# Does this region have postal codes?
|
291
303
|
def has_zip?
|
292
|
-
format["show"]&.include?("{zip}")
|
304
|
+
!!format["show"]&.include?("{zip}")
|
293
305
|
end
|
294
306
|
|
295
307
|
# Is this Region considered a "province" (political subdivision of a "country")?
|
@@ -357,12 +369,12 @@ module Worldwide
|
|
357
369
|
end
|
358
370
|
|
359
371
|
# is the given postal code value valid for this region?
|
360
|
-
def valid_zip?(zip)
|
372
|
+
def valid_zip?(zip, partial_match: false)
|
361
373
|
normalized = Zip.normalize(
|
362
|
-
country_code: province? ? parent.iso_code : iso_code,
|
374
|
+
country_code: province? && parent.iso_code ? parent.iso_code : iso_code,
|
363
375
|
zip: zip,
|
364
376
|
)
|
365
|
-
valid_normalized_zip?(normalized)
|
377
|
+
valid_normalized_zip?(normalized, partial_match: partial_match)
|
366
378
|
end
|
367
379
|
|
368
380
|
# are zones optional for this region?
|
@@ -46,6 +46,9 @@ module Worldwide
|
|
46
46
|
@regions << current_region
|
47
47
|
end
|
48
48
|
|
49
|
+
if parent.present? && current_region.parent != parent
|
50
|
+
current_region.parent = parent
|
51
|
+
end
|
49
52
|
parent&.add_zone(current_region)
|
50
53
|
return current_region if children.nil?
|
51
54
|
|
@@ -62,6 +65,8 @@ module Worldwide
|
|
62
65
|
region.currency = Worldwide.currency(code: currency_code) unless currency_code.nil?
|
63
66
|
region.flag = spec["emoji"]
|
64
67
|
region.format = spec["format"]
|
68
|
+
region.group = spec["group"]
|
69
|
+
region.group_name = spec["group_name"]
|
65
70
|
region.hide_provinces_from_addresses = spec["hide_provinces_from_addresses"] || false
|
66
71
|
region.languages = spec["languages"]
|
67
72
|
region.partial_zip_regex = spec["partial_zip_regex"]
|
data/lib/worldwide/version.rb
CHANGED
data/worldwide.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.email = "developers@shopify.com"
|
12
12
|
|
13
13
|
spec.summary = "Internationalization and localization APIs"
|
14
|
-
spec.description = "APIs
|
14
|
+
spec.description = "APIs for I18n, I10n, and mailing address operations in Ruby."
|
15
15
|
spec.homepage = "https://github.com/Shopify/worldwide"
|
16
16
|
|
17
17
|
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: worldwide
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.8'
|
55
|
-
description: APIs
|
55
|
+
description: APIs for I18n, I10n, and mailing address operations in Ruby.
|
56
56
|
email: developers@shopify.com
|
57
57
|
executables: []
|
58
58
|
extensions: []
|