lib/worldwide/region.rb in worldwide-0.11.0 vs lib/worldwide/region.rb in worldwide-0.14.0
- old
+ new
@@ -17,10 +17,11 @@
:building_number_required,
:currency,
:example_city,
:flag,
:format,
+ :format_extended,
:group,
:group_name,
:cldr_code,
:iso_code,
:languages,
@@ -30,10 +31,11 @@
:unit_system,
:zip_autofill_enabled,
:zip_example,
:zip_regex,
:zip_requirement,
+ :additional_address_fields,
]
# A region may have more than one parent.
# For example, Puerto Rico (PR/US-PR) is associated with both the US and the Caribbean (029)
attr_accessor :parents
@@ -71,13 +73,19 @@
# - address1_with_unit: address line 1 including a subpremise (unit, apartment, etc.)
# - edit: the fields to present on an address input form
# - show: how to arrange the fields when formatting an address for display
attr_accessor :format
+ # Hash of strings denoting how to format an address in this region, including substitute and/or additional fields.
+ # The format is described in https://shopify.engineering/handling-addresses-from-all-around-the-world
+ # - edit: the fields to present on an address input form
+ # - show: how to arrange the fields when formatting an address for display
+ attr_accessor :format_extended
+
# The string that results from appending " Countries" to the adjectival form of the {group_name}
# @example
- # CountryDb.country(code: "CA").group == "North American Countries"
+ # Worldwide.region(code: "CA").group == "North American Countries"
attr_accessor :group
# The continent that this region is part of.
attr_accessor :group_name
@@ -99,17 +107,15 @@
attr_accessor :languages
# The code used by the legacy Shopify ecosystem for this region.
# E.g., for MX-CMX it will return "DF".
# This code should _never_ be shown in the user interface.
- # This is the code that was traditionally returned by "country_db".
attr_reader :legacy_code
# The name used by the legacy Shopify ecosystem for this region.
# E.g., "Sao Tome And[sic] Principe" for "ST".
# This name should _never_ be shown in the user interface.
- # This name is the name that was traditionally returned by "country_db".
attr_reader :legacy_name
# Other names that may be used to refer to this region.
# E.g., "Czech Republic" is also known as "Czechia".
attr_accessor :name_alternates
@@ -189,10 +195,13 @@
attr_reader :zones
# If true, then the province is optional for addresses in this region.
attr_accessor :province_optional
+ # A hash of additional address fields and the rules for concatening them into the standard fields
+ attr_accessor :additional_address_fields
+
def initialize(
alpha_three: nil,
continent: false,
country: false,
deprecated: false,
@@ -224,14 +233,16 @@
@short_name = short_name
@tax_name = tax_name
@tax_rate = tax_rate
@use_zone_code_as_short_name = use_zone_code_as_short_name
+ @additional_address_fields = {}
@building_number_required = false
@building_number_may_be_in_address2 = false
@currency = nil
@flag = nil
@format = {}
+ @format_extended = {}
@group = nil
@group_name = nil
@languages = []
@neighbours = []
@partial_zip_regex = nil