worldwide 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +1 -1
- data/db/data/regions/IT.yml +1 -0
- data/lib/worldwide/region.rb +49 -7
- data/lib/worldwide/regions.rb +2 -2
- data/lib/worldwide/regions_loader.rb +2 -3
- data/lib/worldwide/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70f7f2806122734340656c024d816ec4028060de514b5dc4773529ce8bff4f37
|
4
|
+
data.tar.gz: 3c5c2237879ab05f1a77505432bca89ad50e9d5667ff1d1951b501c07f43050e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f8e9fa1416ccc24d3818e609acf7d05da6534cdb9b1e780af496151559bbb5e73540df416d85d554a3083a5add5691df2ab512fa023da3ca43d85251a89c18d
|
7
|
+
data.tar.gz: d55d1ed819560e45099c6ae1fc9e1cc5f62e0a6b62c4e9b24aa97daa78b7aae0e6cb8636dc0b6086ca5ba7f3a715badc0e7d4c60ddde09df49cb2b2c00677e8c
|
data/CHANGELOG.md
CHANGED
@@ -28,6 +28,16 @@ Nil.
|
|
28
28
|
|
29
29
|
---
|
30
30
|
|
31
|
+
[0.3.0] - 2023-11-03
|
32
|
+
- Add code alternates for Japan [#23](https://github.com/Shopify/worldwide/pull/23)
|
33
|
+
- Add code alternates for Puerto Rico [#24](https://github.com/Shopify/worldwide/pull/24)
|
34
|
+
- Record multiple parents per region [#27](https://github.com/Shopify/worldwide/pull/27)
|
35
|
+
- Add region.building_number_may_be_in_address2 [#28](https://github.com/Shopify/worldwide/pull/28)
|
36
|
+
- Lookup by parent-child ISO and CLDR codes for dual-status territories
|
37
|
+
[#29](https://github.com/Shopify/worldwide/pull/29)
|
38
|
+
- Handle ISO_CODE only zones lookup [#26](https://github.com/Shopify/worldwide/pull/26)
|
39
|
+
|
40
|
+
|
31
41
|
[0.2.0] - 2023-11-01
|
32
42
|
|
33
43
|
- Add Region#group and Region#group_name [#15](https://github.com/Shopify/worldwide/pull/15)
|
data/Gemfile.lock
CHANGED
data/db/data/regions/IT.yml
CHANGED
data/lib/worldwide/region.rb
CHANGED
@@ -34,7 +34,9 @@ module Worldwide
|
|
34
34
|
:zip_requirement,
|
35
35
|
]
|
36
36
|
|
37
|
-
|
37
|
+
# A region may have more than one parent.
|
38
|
+
# For example, Puerto Rico (PR/US-PR) is associated with both the US and the Caribbean (029)
|
39
|
+
attr_accessor :parents
|
38
40
|
|
39
41
|
# ISO-3166 three-letter code for this region, if there is one.
|
40
42
|
# Otherwise, nil.
|
@@ -45,6 +47,10 @@ module Worldwide
|
|
45
47
|
# If we require a building number in an address, then this will be true.
|
46
48
|
attr_accessor :building_number_required
|
47
49
|
|
50
|
+
# In some countries, an address may have the building number in address2.
|
51
|
+
# If we are allowed to have a building number in address2, then this will be true.
|
52
|
+
attr_accessor :building_number_may_be_in_address2
|
53
|
+
|
48
54
|
# Alternate codes which may be used to designate this region
|
49
55
|
attr_accessor :code_alternates
|
50
56
|
|
@@ -217,6 +223,7 @@ module Worldwide
|
|
217
223
|
@use_zone_code_as_short_name = use_zone_code_as_short_name
|
218
224
|
|
219
225
|
@building_number_required = false
|
226
|
+
@building_number_may_be_in_address2 = false
|
220
227
|
@currency = nil
|
221
228
|
@flag = nil
|
222
229
|
@format = {}
|
@@ -236,7 +243,7 @@ module Worldwide
|
|
236
243
|
@zip_prefixes = []
|
237
244
|
@zip_regex = nil
|
238
245
|
|
239
|
-
@
|
246
|
+
@parents = [].to_set
|
240
247
|
@zones = []
|
241
248
|
end
|
242
249
|
|
@@ -249,12 +256,18 @@ module Worldwide
|
|
249
256
|
def add_zone(region)
|
250
257
|
return if @zones.include?(region)
|
251
258
|
|
252
|
-
region.
|
259
|
+
region.parents << self
|
253
260
|
@zones.append(region)
|
254
261
|
end
|
255
262
|
|
256
263
|
# Attributes
|
257
264
|
|
265
|
+
def associated_country
|
266
|
+
return self if country?
|
267
|
+
|
268
|
+
parent_country
|
269
|
+
end
|
270
|
+
|
258
271
|
# The value with which to autofill the zip, if this region has zip autofill active;
|
259
272
|
# otherwise, nil.
|
260
273
|
def autofill_zip
|
@@ -333,7 +346,8 @@ module Worldwide
|
|
333
346
|
|
334
347
|
zones.find do |region|
|
335
348
|
[search_code, alt_search_code].any? do |candidate|
|
336
|
-
candidate == region.
|
349
|
+
candidate == subdivision_code(region.iso_code) ||
|
350
|
+
candidate == region.alpha_three ||
|
337
351
|
candidate == region.iso_code ||
|
338
352
|
candidate == region.legacy_code ||
|
339
353
|
candidate == region.numeric_three ||
|
@@ -371,7 +385,7 @@ module Worldwide
|
|
371
385
|
# is the given postal code value valid for this region?
|
372
386
|
def valid_zip?(zip, partial_match: false)
|
373
387
|
normalized = Zip.normalize(
|
374
|
-
country_code: province? &&
|
388
|
+
country_code: province? && associated_country.iso_code ? associated_country.iso_code : iso_code,
|
375
389
|
zip: zip,
|
376
390
|
)
|
377
391
|
valid_normalized_zip?(normalized, partial_match: partial_match)
|
@@ -384,6 +398,21 @@ module Worldwide
|
|
384
398
|
|
385
399
|
private
|
386
400
|
|
401
|
+
def answers_to_cldr_code(search_code)
|
402
|
+
return false if Util.blank?(search_code) || Util.blank?(cldr_code)
|
403
|
+
return true if search_code.casecmp(cldr_code).zero?
|
404
|
+
|
405
|
+
pc = parent_country
|
406
|
+
"#{pc&.cldr_code&.downcase}#{cldr_code.downcase}" == search_code.downcase
|
407
|
+
end
|
408
|
+
|
409
|
+
def answers_to_iso_code(search_code)
|
410
|
+
return true if search_code == iso_code
|
411
|
+
|
412
|
+
pc = parent_country
|
413
|
+
"#{pc&.iso_code}-#{iso_code}" == search_code
|
414
|
+
end
|
415
|
+
|
387
416
|
def cross_border_zip_includes_province?(zip:, province_code:)
|
388
417
|
return false unless country?
|
389
418
|
|
@@ -408,11 +437,17 @@ module Worldwide
|
|
408
437
|
INSPECTION_FIELDS.map { |field_name| "@#{field_name}=#{send(field_name).inspect}" }.join(", ")
|
409
438
|
end
|
410
439
|
|
440
|
+
def parent_country
|
441
|
+
parents.find(&:country?)
|
442
|
+
end
|
443
|
+
|
411
444
|
# Checks whether the given value is acceptable according to the regular expression defined for the country.
|
412
445
|
# @param value [String] for the postal code
|
413
446
|
# @return [Boolean]
|
414
447
|
def passes_country_zip_regexp?(value:, partial_match: false)
|
415
|
-
|
448
|
+
if province?
|
449
|
+
return associated_country.send(:passes_country_zip_regexp?, value: value, partial_match: partial_match)
|
450
|
+
end
|
416
451
|
|
417
452
|
return false if partial_match && partial_zip_regex.nil?
|
418
453
|
|
@@ -445,11 +480,18 @@ module Worldwide
|
|
445
480
|
end&.first
|
446
481
|
end
|
447
482
|
|
483
|
+
def subdivision_code(iso_code)
|
484
|
+
return iso_code if iso_code.nil? || iso_code.length < 3
|
485
|
+
|
486
|
+
country_code, subdivision_code = iso_code.split("-")
|
487
|
+
return subdivision_code if country_code.casecmp(associated_country.iso_code).zero?
|
488
|
+
end
|
489
|
+
|
448
490
|
def valid_normalized_zip?(normalized, province_code: nil, partial_match: false)
|
449
491
|
if country?
|
450
492
|
country = self
|
451
493
|
elsif province?
|
452
|
-
country =
|
494
|
+
country = associated_country
|
453
495
|
province_code ||= legacy_code
|
454
496
|
end
|
455
497
|
|
data/lib/worldwide/regions.rb
CHANGED
@@ -32,13 +32,13 @@ module Worldwide
|
|
32
32
|
search_code = cldr.to_s.upcase
|
33
33
|
|
34
34
|
@regions.find do |r|
|
35
|
-
r.
|
35
|
+
r.send(:answers_to_cldr_code, search_code)
|
36
36
|
end
|
37
37
|
elsif code
|
38
38
|
search_code = code.to_s.upcase
|
39
39
|
|
40
40
|
@regions.find do |r|
|
41
|
-
r.
|
41
|
+
r.send(:answers_to_iso_code, search_code) || r.alpha_three == search_code || r.numeric_three == search_code
|
42
42
|
end
|
43
43
|
else # search by name
|
44
44
|
search_name = name.upcase
|
@@ -46,9 +46,7 @@ module Worldwide
|
|
46
46
|
@regions << current_region
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
current_region.parent = parent
|
51
|
-
end
|
49
|
+
current_region.parents << parent if Util.present?(parent)
|
52
50
|
parent&.add_zone(current_region)
|
53
51
|
return current_region if children.nil?
|
54
52
|
|
@@ -61,6 +59,7 @@ module Worldwide
|
|
61
59
|
|
62
60
|
def apply_territory_attributes(region, spec)
|
63
61
|
region.building_number_required = spec["building_number_required"] || true
|
62
|
+
region.building_number_may_be_in_address2 = spec["building_number_may_be_in_address2"] || false
|
64
63
|
currency_code = spec["currency"]
|
65
64
|
region.currency = Worldwide.currency(code: currency_code) unless currency_code.nil?
|
66
65
|
region.flag = spec["emoji"]
|
data/lib/worldwide/version.rb
CHANGED
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.3.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-
|
11
|
+
date: 2023-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|