worldwide 1.8.0 → 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: 10690cd44e02d998b8ca4ee789e61249a38ea26de8170510ccdd9db4eb025f19
4
- data.tar.gz: 0700e6a0e322cccab5562e430ccc5d44a898759e51b1886f61e3d92c079315fb
3
+ metadata.gz: 1a8ccc240633a76f5c8a4873ce0b1034429bc746e8acb52b1813297aecf4f35f
4
+ data.tar.gz: c82d68acb68d959683b2a19c6dd54152e5ad76e1dbfe65b6898c16d82a0a26b9
5
5
  SHA512:
6
- metadata.gz: 7fb8e5ca9731b7c01e2c0326a6196200a58b313d9ec4e5fce2d32a6deafa442f49da95afac4c5cf6d465ade8c4a8c0665aabf8dcea576c48133fde457a9ff06a
7
- data.tar.gz: 7bac429acb03a74cb3f408d606dc4691c164b72d6e619079f7782a420bdad4208f37498a9b1d29edf898b89ab3d5de72c81512a5bfcde1b9ab27304ddcf70f78
6
+ metadata.gz: 3101d0215fcfc3f1e488571ce66d4e3301f6a9c49124efa162704332dd1ca551cb0adf961f3644621e687486a1c7525a6d2b96d759e51dcce308ed930a35f735
7
+ data.tar.gz: 76b817ece1b5ae48d6a4eaf92c262c8e22029068ffeb10519ff18252e839f4b54b8455c768b0abe5eaf51c66f1232657b11cf0ed2836a447f184f82e702247cc
data/CHANGELOG.md CHANGED
@@ -26,9 +26,15 @@ 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
 
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
+
32
38
  ## [1.8.0] - 2024-08-09
33
39
  - Bump Ruby to 3.3.1; drop support for 3.0.x [#264](https://github.com/Shopify/worldwide/pull/264)
34
40
  - Add support for partial zip matching for SG [#271](https://github.com/Shopify/worldwide/pull/271)
data/Gemfile.lock CHANGED
@@ -13,7 +13,7 @@ GIT
13
13
  PATH
14
14
  remote: .
15
15
  specs:
16
- worldwide (1.8.0)
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
@@ -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.8.0"
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
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.8.0
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-09 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
@@ -8505,7 +8505,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
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