lib/worldwide/region.rb in worldwide-0.1.1 vs lib/worldwide/region.rb in worldwide-0.2.0

- old
+ new

@@ -17,10 +17,12 @@ :building_number_required, :currency, :example_city, :flag, :format, + :group, + :group_name, :cldr_code, :iso_code, :languages, :neighbours, :numeric_three, @@ -63,10 +65,18 @@ # - 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 + # The string that results from appending " Countries" to the adjectival form of the {group_name} + # @example + # CountryDb.country(code: "CA").group == "North American Countries" + attr_accessor :group + + # The continent that this region is part of. + attr_accessor :group_name + # If this flag is set, then we support provinces "under the hood" for this country, but we do not # show them as part of a formatted address. If the province is missing, we will auto-infer it # based on the zip (note that this auto-inference may be wrong for some addresses near a border). attr_accessor :hide_provinces_from_addresses @@ -208,10 +218,12 @@ @building_number_required = false @currency = nil @flag = nil @format = {} + @group = nil + @group_name = nil @languages = [] @neighbours = [] @partial_zip_regex = nil @phone_number_prefix = nil @tags = [] @@ -287,11 +299,11 @@ end end # Does this region have postal codes? def has_zip? - format["show"]&.include?("{zip}") + !!format["show"]&.include?("{zip}") end # Is this Region considered a "province" (political subdivision of a "country")? def province? @province @@ -355,15 +367,15 @@ REQUIRED == zip_requirement end end # is the given postal code value valid for this region? - def valid_zip?(zip) + def valid_zip?(zip, partial_match: false) normalized = Zip.normalize( - country_code: province? ? parent.iso_code : iso_code, + country_code: province? && parent.iso_code ? parent.iso_code : iso_code, zip: zip, ) - valid_normalized_zip?(normalized) + valid_normalized_zip?(normalized, partial_match: partial_match) end # are zones optional for this region? def province_optional? province_optional || !@zones&.any?(&:province?)