worldwide 1.7.5 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73b7ac8bf90c9e5184a3422d4672334fc1c66496729fa1014ffac15c6f86960d
4
- data.tar.gz: 1e4eb70d0226a58f54a9a59723e6c5940460f41a48e098c06a5a63c517e9d6dd
3
+ metadata.gz: 1a8ccc240633a76f5c8a4873ce0b1034429bc746e8acb52b1813297aecf4f35f
4
+ data.tar.gz: c82d68acb68d959683b2a19c6dd54152e5ad76e1dbfe65b6898c16d82a0a26b9
5
5
  SHA512:
6
- metadata.gz: a7f52ac2eb268b18a05aa816905cc4112b13d5efbccc64001d589fd696394c7e1f0e938654edf16d7fb38a9efa5d2379593081d81004c6afbb722de3039d7a41
7
- data.tar.gz: 93ae987d62a19e4afbf7720a861f9a470e18b97d78a01ff1df9d470af2aadaa741793b3c0c7e56fb35dfd609f713311d26429d1cc213bc69ebee2fedf8e7f4d9
6
+ metadata.gz: 3101d0215fcfc3f1e488571ce66d4e3301f6a9c49124efa162704332dd1ca551cb0adf961f3644621e687486a1c7525a6d2b96d759e51dcce308ed930a35f735
7
+ data.tar.gz: 76b817ece1b5ae48d6a4eaf92c262c8e22029068ffeb10519ff18252e839f4b54b8455c768b0abe5eaf51c66f1232657b11cf0ed2836a447f184f82e702247cc
@@ -11,7 +11,7 @@ jobs:
11
11
  matrix:
12
12
  gemfile:
13
13
  - Gemfile
14
- ruby: ["3.0", "3.1", "3.2"]
14
+ ruby: ["3.1", "3.2", "3.3"]
15
15
  env:
16
16
  BUNDLE_GEMFILE: ${{ matrix.gemfile }}
17
17
  steps:
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.2.2
1
+ 3.3.1
data/CHANGELOG.md CHANGED
@@ -26,10 +26,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
26
26
  - Security in case of vulnerabilities.
27
27
 
28
28
  ## [Unreleased]
29
+ - Nil.
29
30
 
30
31
  ---
31
32
 
32
- ## [1.7.5] = 2024-08-01
33
+ ## [1.9.0] - 2024-08-12
34
+ - add support for additional address fields streetName, streetNumber in DE [#273](https://github.com/Shopify/worldwide/pull/273)
35
+ - set additional_field neighborhood as required in BR [#279](https://github.com/Shopify/worldwide/pull/279)
36
+
37
+
38
+ ## [1.8.0] - 2024-08-09
39
+ - Bump Ruby to 3.3.1; drop support for 3.0.x [#264](https://github.com/Shopify/worldwide/pull/264)
40
+ - Add support for partial zip matching for SG [#271](https://github.com/Shopify/worldwide/pull/271)
41
+
42
+ ## [1.7.5] - 2024-08-01
33
43
  - Update legacy timezone mappings for America/Indianapolis and Asia/Calcutta [#267](https://github.com/Shopify/worldwide/pull/267)
34
44
 
35
45
  ## [1.7.4] - 2024-08-01
data/Gemfile.lock CHANGED
@@ -13,7 +13,7 @@ GIT
13
13
  PATH
14
14
  remote: .
15
15
  specs:
16
- worldwide (1.7.5)
16
+ worldwide (1.9.0)
17
17
  activesupport (>= 7.0)
18
18
  i18n
19
19
  phonelib (~> 0.8)
@@ -35,6 +35,7 @@ additional_address_fields:
35
35
  required: true
36
36
  - name: line2
37
37
  - name: neighborhood
38
+ required: true
38
39
  combined_address_format:
39
40
  default:
40
41
  address1:
@@ -20,12 +20,25 @@ languages:
20
20
  - de
21
21
  - en
22
22
  example_address:
23
- address1: Willy-Brandt-Straße 1
23
+ address1: Willy-Brandt-Straße 1
24
24
  city: Berlin
25
25
  zip: '10557'
26
26
  phone: "+49 30 182722720"
27
27
  format:
28
28
  edit: "{country}_{firstName}{lastName}_{company}_{address1}_{address2}_{zip}{city}_{phone}"
29
29
  show: "{firstName} {lastName}_{company}_{address1}_{address2}_{zip} {city}_{country}_{phone}"
30
+ format_extended:
31
+ edit: "{country}_{firstName}{lastName}_{company}_{streetName}{streetNumber}_{address2}_{zip}{city}_{phone}"
32
+ additional_address_fields:
33
+ - name: streetName
34
+ required: true
35
+ - name: streetNumber
36
+ required: true
37
+ combined_address_format:
38
+ default:
39
+ address1:
40
+ - key: streetName
41
+ - key: streetNumber
42
+ decorator: " "
30
43
  emoji: "\U0001F1E9\U0001F1EA"
31
44
  timezone: Europe/Berlin
@@ -8,6 +8,7 @@ tax_name: GST
8
8
  group: Asian Countries
9
9
  group_name: Asia
10
10
  zip_regex: "^\\d{6}$"
11
+ partial_zip_regex: "^\\d{2}$"
11
12
  zip_example: '546080'
12
13
  phone_number_prefix: 65
13
14
  building_number_required: true
@@ -4,32 +4,27 @@ require "worldwide/calendar/gregorian"
4
4
 
5
5
  module Worldwide
6
6
  module Calendar
7
- class << self
8
- def first_week_day(territory_code)
9
- first_day_data[territory_code.to_sym] || first_day_data.fetch(:"001")
7
+ data = YAML.load_file(File.join(Worldwide::Paths::CLDR_ROOT, "week_data.yml"))["first_day"]
8
+ weekday_numbers = {
9
+ sun: 0,
10
+ mon: 1,
11
+ tue: 2,
12
+ wed: 3,
13
+ thu: 4,
14
+ fri: 5,
15
+ sat: 6,
16
+ }
17
+ FIRST_DAY_DATA = data.each_with_object({}) do |(day, territories), memo|
18
+ territories.each do |territory|
19
+ memo[territory.to_sym] = weekday_numbers.fetch(day.to_sym)
10
20
  end
21
+ end
22
+ FIRST_DAY_DATA.freeze
23
+ private_constant :FIRST_DAY_DATA
11
24
 
12
- private
13
-
14
- def first_day_data
15
- return @first_day_data if defined?(@first_day_data)
16
-
17
- weekday_numbers = {
18
- sun: 0,
19
- mon: 1,
20
- tue: 2,
21
- wed: 3,
22
- thu: 4,
23
- fri: 5,
24
- sat: 6,
25
- }
26
-
27
- data = YAML.load_file(File.join(Worldwide::Paths::CLDR_ROOT, "week_data.yml"))["first_day"]
28
- @first_day_data = data.each_with_object({}) do |(day, territories), memo|
29
- territories.each do |territory|
30
- memo[territory.to_sym] = weekday_numbers.fetch(day.to_sym)
31
- end
32
- end
25
+ class << self
26
+ def first_week_day(territory_code)
27
+ FIRST_DAY_DATA[territory_code.to_sym] || FIRST_DAY_DATA.fetch(:"001")
33
28
  end
34
29
  end
35
30
  end
@@ -26,7 +26,10 @@ module Worldwide
26
26
  private
27
27
 
28
28
  def cldr_defined_parents
29
- @cldr_defined_parents ||= YAML.load_file(File.join(Worldwide::Paths::CLDR_ROOT, "parent_locales.yml")).to_h { |k, v| [k.to_sym, v.to_sym] }
29
+ @cldr_defined_parents ||= YAML.load_file(
30
+ File.join(Worldwide::Paths::CLDR_ROOT, "parent_locales.yml"),
31
+ symbolize_names: true,
32
+ ).transform_values(&:to_sym)
30
33
  end
31
34
 
32
35
  def ancestry(locale)
@@ -4,15 +4,24 @@ module Worldwide
4
4
  module Currencies
5
5
  include Enumerable
6
6
  extend self
7
- CURRENCIES_FILE_PATH = File.join(Worldwide::Paths::CLDR_ROOT, "locales", "en", "currencies.yml")
8
- CURRENCY_CODES_FILE_PATH = File.join(Worldwide::Paths::OTHER_DATA_ROOT, "currency", "codes.yml")
7
+
8
+ CURRENCY_CODES = YAML.safe_load_file(
9
+ File.join(Worldwide::Paths::OTHER_DATA_ROOT, "currency/codes.yml"),
10
+ freeze: true,
11
+ )
12
+ private_constant :CURRENCY_CODES
13
+
14
+ NUMERIC_THREE_TO_ALPHA_THREE_DB = CURRENCY_CODES.to_h do |key, value|
15
+ [value["three_digit_code"].to_i, key.to_s.upcase.to_sym]
16
+ end.freeze
17
+ private_constant :NUMERIC_THREE_TO_ALPHA_THREE_DB
9
18
 
10
19
  def each(&block)
11
- all_currencies.each(&block)
20
+ ALL_CURRENCIES.each(&block)
12
21
  end
13
22
 
14
23
  def all
15
- all_currencies
24
+ ALL_CURRENCIES
16
25
  end
17
26
 
18
27
  # Convert ISO-4217 numeric-three code to ISO-4217 alpha-three code
@@ -23,39 +32,25 @@ module Worldwide
23
32
  else
24
33
  numeric_code&.to_s&.to_i
25
34
  end
26
- numeric_three_to_alpha_three_db[lookup_code]&.to_s
35
+ NUMERIC_THREE_TO_ALPHA_THREE_DB[lookup_code]&.to_s
27
36
  end
28
37
 
29
38
  # Convert ISO-4217 alpha-three code to ISO-4217 numeric-three code
30
39
  # Note that we support some currencies (e.g. JEP) that are not recognized by ISO,
31
40
  # and there is no numeric-three code for these currencies, so nil will be returned.
32
41
  def numeric_code_for(alpha_code)
33
- currency_codes.dig(alpha_code&.to_s&.upcase, "three_digit_code")&.to_i
34
- end
35
-
36
- private
37
-
38
- def all_currencies
39
- @all_currencies ||= begin
40
- currencies = {}
41
- YAML.load_file(CURRENCIES_FILE_PATH)["en"]["currencies"].map do |code, _name|
42
- currencies[code] = Currency.new(code: code)
43
- end.sort_by(&:currency_code)
44
- end
42
+ CURRENCY_CODES.dig(alpha_code&.to_s&.upcase, "three_digit_code")&.to_i
45
43
  end
46
44
 
47
- def currency_codes
48
- @currency_codes ||= YAML.safe_load_file(CURRENCY_CODES_FILE_PATH)
49
- end
50
-
51
- def map_alpha_three_to_numeric_three
52
- currency_codes
53
- end
54
-
55
- def numeric_three_to_alpha_three_db
56
- @map_numeric_three_to_alpha_three ||= currency_codes.to_h do |key, value|
57
- [value["three_digit_code"].to_i, key.to_s.upcase.to_sym]
58
- end
45
+ currencies = YAML.load_file(
46
+ File.join(Worldwide::Paths::CLDR_ROOT, "locales/en/currencies.yml"),
47
+ freeze: true,
48
+ )
49
+ ALL_CURRENCIES = currencies["en"]["currencies"].map do |code, _name|
50
+ Currency.new(code: code)
59
51
  end
52
+ ALL_CURRENCIES.sort_by!(&:currency_code)
53
+ ALL_CURRENCIES.freeze
54
+ private_constant :ALL_CURRENCIES
60
55
  end
61
56
  end
@@ -2,13 +2,6 @@
2
2
 
3
3
  module Worldwide
4
4
  class Locale
5
- class << self
6
- def unknown
7
- # Special CLDR value
8
- @unknown = Locale.new("und")
9
- end
10
- end
11
-
12
5
  attr_reader :code
13
6
 
14
7
  def initialize(code)
@@ -20,6 +13,10 @@ module Worldwide
20
13
  @name_cache = {}
21
14
  end
22
15
 
16
+ # Special CLDR value
17
+ @unknown = new("und")
18
+ singleton_class.attr_reader(:unknown)
19
+
23
20
  def language_subtag
24
21
  code.to_s.split("-", 2).first
25
22
  end
@@ -287,7 +287,7 @@ module Worldwide
287
287
  end
288
288
 
289
289
  def world_yml
290
- @world_yml ||= YAML.load_file(File.join(Worldwide::Paths::DB_DATA_ROOT, "world.yml"))
290
+ @world_yml ||= YAML.load_file(File.join(Worldwide::Paths::DB_DATA_ROOT, "world.yml"), freeze: true)
291
291
  end
292
292
  end
293
293
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Worldwide
4
- VERSION = "1.7.5"
4
+ VERSION = "1.9.0"
5
5
  end
data/lib/worldwide.rb CHANGED
@@ -17,8 +17,8 @@ require "worldwide/address_validator"
17
17
  require "worldwide/calendar"
18
18
  require "worldwide/cldr"
19
19
  require "worldwide/cldr/context_transforms"
20
- require "worldwide/currencies"
21
20
  require "worldwide/currency"
21
+ require "worldwide/currencies"
22
22
  require "worldwide/deprecated_time_zone_mapper"
23
23
  require "worldwide/discounts"
24
24
  require "worldwide/fields"
@@ -109,4 +109,6 @@ module Worldwide
109
109
  Units
110
110
  end
111
111
  end
112
+
113
+ Regions.instance # eagerload
112
114
  end
data/worldwide.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
26
26
 
27
- spec.required_ruby_version = ">= 3.0.0"
27
+ spec.required_ruby_version = ">= 3.1.0"
28
28
 
29
29
  spec.add_dependency("activesupport", ">= 7.0")
30
30
  spec.add_dependency("i18n")
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: 1.7.5
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-01 00:00:00.000000000 Z
11
+ date: 2024-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -8498,14 +8498,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
8498
8498
  requirements:
8499
8499
  - - ">="
8500
8500
  - !ruby/object:Gem::Version
8501
- version: 3.0.0
8501
+ version: 3.1.0
8502
8502
  required_rubygems_version: !ruby/object:Gem::Requirement
8503
8503
  requirements:
8504
8504
  - - ">="
8505
8505
  - !ruby/object:Gem::Version
8506
8506
  version: '0'
8507
8507
  requirements: []
8508
- rubygems_version: 3.5.16
8508
+ rubygems_version: 3.5.17
8509
8509
  signing_key:
8510
8510
  specification_version: 4
8511
8511
  summary: Internationalization and localization APIs