Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
inherit_gem:
rubocop-shopify: rubocop.yml

require:
plugins:
- rubocop-minitest
- rubocop-performance
- rubocop-rake
Expand Down
75 changes: 41 additions & 34 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ GEM
mutex_m
tzinfo (~> 2.0)
ansi (1.5.0)
ast (2.4.2)
ast (2.4.3)
base64 (0.1.1)
bigdecimal (3.1.4)
builder (3.2.4)
Expand All @@ -44,8 +44,10 @@ GEM
ruby2_keywords
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json (2.7.1)
language_server-protocol (3.17.0.3)
json (2.18.1)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
logger (1.7.0)
method_source (1.1.0)
minitest (5.17.0)
minitest-focus (1.3.1)
Expand All @@ -62,12 +64,12 @@ GEM
racc (~> 1.4)
nokogiri (1.18.9-x86_64-linux-gnu)
racc (~> 1.4)
parallel (1.24.0)
parser (3.3.0.5)
parallel (1.27.0)
parser (3.3.10.2)
ast (~> 2.4.1)
racc
phonelib (0.8.7)
prettier_print (1.2.0)
prism (1.9.0)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
Expand All @@ -81,47 +83,52 @@ GEM
rake (13.0.6)
rake-compiler (1.2.1)
rake
regexp_parser (2.9.0)
rexml (3.2.8)
strscan (>= 3.0.9)
rubocop (1.62.1)
rbs (3.10.3)
logger
tsort
regexp_parser (2.11.3)
rubocop (1.84.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.49.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.2)
parser (>= 3.3.0.4)
rubocop-minitest (0.27.0)
rubocop (>= 0.90, < 2.0)
rubocop-performance (1.16.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-shopify (2.12.0)
rubocop (~> 1.44)
ruby-lsp (0.3.8)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.49.0)
parser (>= 3.3.7.2)
prism (~> 1.7)
rubocop-minitest (0.39.1)
lint_roller (~> 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.38.0, < 2.0)
rubocop-performance (1.26.1)
lint_roller (~> 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.47.1, < 2.0)
rubocop-rake (0.7.1)
lint_roller (~> 1.1)
rubocop (>= 1.72.1)
rubocop-shopify (2.18.0)
rubocop (~> 1.62)
ruby-lsp (0.26.7)
language_server-protocol (~> 3.17.0)
sorbet-runtime
syntax_tree (>= 5.0.0, < 6)
prism (>= 1.2, < 2.0)
rbs (>= 3, < 5)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
sorbet-runtime (0.5.10648)
stringio (3.1.0)
strscan (3.1.0)
syntax_tree (5.3.0)
prettier_print (>= 1.2.0)
thor (1.2.1)
tsort (0.2.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.2.0)

PLATFORMS
arm64-darwin-21
Expand Down
6 changes: 3 additions & 3 deletions lib/worldwide/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def build_address_format_array(additional_lines:, excluded_fields:)
result << line unless blank?(line.join)
end

result + additional_lines.map { |x| [x] }
result + additional_lines.zip
end

# Returns a hash containing the values for each address field
Expand Down Expand Up @@ -348,7 +348,7 @@ def fill_in_fields(fields:, address_data:)
def japan_with_non_japanese_script?
text = build_formatted_address_data.values.join

country_code == "JP" && Worldwide::Scripts.identify(text: text).intersection(JAPANESE_SCRIPTS).empty?
country_code == "JP" && !Worldwide::Scripts.identify(text: text).intersect?(JAPANESE_SCRIPTS)
end

def normalize_city
Expand Down Expand Up @@ -457,7 +457,7 @@ def strip_extra_chars(lines:, excluded_fields:)
# - `〒` ("yuubin" mark) is a prefix that's prepended to the postal code (zip)
# If the associated field is excluded/empty, we need to suppress the associated special character.
def strip_extra_japanese_chars(line:, excluded_fields:)
return nil if line.nil?
return if line.nil?

line.map do |field|
stripped = field
Expand Down
1 change: 1 addition & 0 deletions lib/worldwide/address_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class AddressValidator

class << self
extend Forwardable

def_delegators :instance, :errors, :valid?
end

Expand Down
8 changes: 4 additions & 4 deletions lib/worldwide/cldr/date_format_pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,28 @@ def tokenize(format)
UNQUOTED_LITERAL = /[^a-zA-Z']+/

def parse_field(format)
return nil unless format.start_with?(PATTERN_FIELD)
return unless format.start_with?(PATTERN_FIELD)

match = PATTERN_FIELD.match(format)
[Field.from(match[0]), match.end(0)]
end

def parse_single_quote(format)
return nil unless format.start_with?(SINGLE_QUOTE_LITERAL)
return unless format.start_with?(SINGLE_QUOTE_LITERAL)

match = SINGLE_QUOTE_LITERAL.match(format)
[Literal.new("'"), match.end(0)]
end

def parse_quoted_literal(format)
return nil unless format.start_with?(QUOTED_LITERAL)
return unless format.start_with?(QUOTED_LITERAL)

match = QUOTED_LITERAL.match(format)
[Literal.new(match[1].gsub(SINGLE_QUOTE_LITERAL, "'")), match.end(0)]
end

def parse_unquoted_literal(format)
return nil unless format.start_with?(UNQUOTED_LITERAL)
return unless format.start_with?(UNQUOTED_LITERAL)

match = UNQUOTED_LITERAL.match(format)
[Literal.new(match[0]), match.end(0)]
Expand Down
2 changes: 1 addition & 1 deletion lib/worldwide/cldr/fallbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def ancestry(locale)
loop do
if cldr_defined_parents[ancestors.last]
ancestors << cldr_defined_parents[ancestors.last]
elsif I18n::Locale::Tag.tag(ancestors.last).parents.count > 0
elsif I18n::Locale::Tag.tag(ancestors.last).parents.any?
ancestors << I18n::Locale::Tag.tag(ancestors.last).parents.first.to_sym
else
break
Expand Down
2 changes: 1 addition & 1 deletion lib/worldwide/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def i18n_defined?(i18n_config, key)
# we don't want to trigger the backend resolution until after we've determined whether they have set it explicitly.
class_variable = "@@#{key}".to_sym
instance_variable = "@#{key}".to_sym
i18n_config.class.class_variables.include?(class_variable) || i18n_config.instance_variables.include?(instance_variable)
i18n_config.class.class_variable_defined?(class_variable) || i18n_config.instance_variables.include?(instance_variable)
else
i18n_config.key?(key)
end
Expand Down
8 changes: 4 additions & 4 deletions lib/worldwide/currency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def symbol(locale: I18n.locale)
raw_symbol = Worldwide::Cldr.t("currencies.#{@currency_code}.narrow_symbol", default: nil, locale: locale) ||
Worldwide::Cldr.t("currencies.#{@currency_code}.symbol", default: nil, locale: locale)

return nil if raw_symbol.nil?
return if raw_symbol.nil?

# For some locales (e.g., HK), in-market folks have requested that we leave the CLDR behaviour untouched
exceptional_symbol = EXCEPTIONS.fetch(@currency_code.to_sym, nil)
Expand Down Expand Up @@ -154,7 +154,7 @@ def name
private

def combine(amount:, decimal_places:, humanize:, locale:, symbol:)
space = if has_space(locale)
space = if has_space?(locale)
# This is U+00A0, the Unicode non-breaking space character
[160].pack("U*")
else
Expand Down Expand Up @@ -237,7 +237,7 @@ def has_minor_symbol?
end

# Returns true if there should be a space between the amount and the currency symbol
def has_space(locale)
def has_space?(locale)
pattern = Worldwide::Cldr.t("numbers.latn.formats.currency.patterns.default.standard", locale: locale)

# Note that CLDR uses these characters in its currency formats:
Expand All @@ -250,7 +250,7 @@ def has_space(locale)
def minor_symbol
key = @currency_code

return nil unless Currency.minor_symbols.key?(key)
return unless Currency.minor_symbols.key?(key)

Currency.minor_symbols[key]["symbol"]
end
Expand Down
1 change: 1 addition & 0 deletions lib/worldwide/extant_outcodes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ExtantOutcodes

class << self
extend Forwardable

def_delegators :instance, :for_country
end

Expand Down
1 change: 1 addition & 0 deletions lib/worldwide/fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Fields

class << self
extend Forwardable

def_delegators :instance, :field
end

Expand Down
1 change: 1 addition & 0 deletions lib/worldwide/lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Worldwide
module Lists
extend self

# We assume that the data is expected to returned in the same
# order as it is received. We are aware of one counter example,
# Urdu, that we do not support.
Expand Down
6 changes: 3 additions & 3 deletions lib/worldwide/locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def name(locale: I18n.locale, context: :middle_of_sentence, throw: true)
if @name_cache[context].is_a?(I18n::MissingTranslation)
raise @name_cache[context] if throw

return nil
return
end

@name_cache[context]
Expand All @@ -93,7 +93,7 @@ def endonym(context: :middle_of_sentence, throw: true)
if @endonym.is_a?(I18n::MissingTranslation)
raise @endonym if throw

return nil
return
end

@endonym
Expand All @@ -113,7 +113,7 @@ def exonym(target_locale:, context:)
result = lookup(language, locale: target_locale)
if result
transformed = Worldwide::Cldr::ContextTransforms.transform(result, :languages, context, locale: target_locale)
break "#{transformed}#{i > 0 ? territories_suffix(code.to_s) : ""}"
break "#{transformed}#{territories_suffix(code.to_s) if i > 0}"
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions lib/worldwide/region.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def deprecated?
# An Worldwide::Field that can be used to ask about the field, including
# labels, error messages, and an autofill value if there is one.
def field(key:)
return nil unless country?
return unless country?

Worldwide::Fields.field(country_code: iso_code, field_key: key)
end
Expand Down Expand Up @@ -479,7 +479,7 @@ def zip_required?
#
# @return [String, nil] One of "ALPHANUMERIC", "NUMERIC", "NUMERIC_AND_PUNCTUATION", or nil if no zip_example
def zip_type
return nil if zip_example.nil?
return if zip_example.nil?

if zip_example.match?(/[A-Za-z]/)
FORMAT_TYPES[:ALPHANUMERIC]
Expand Down Expand Up @@ -554,15 +554,15 @@ def additional_field_required?(field_name)
field ? !!field["required"] : false
end

def answers_to_cldr_code(search_code)
def answers_to_cldr_code?(search_code)
return false if Util.blank?(search_code) || Util.blank?(cldr_code)
return true if search_code.casecmp(cldr_code).zero?

pc = parent_country
"#{pc&.cldr_code&.downcase}#{cldr_code.downcase}" == search_code.downcase
end

def answers_to_iso_code(search_code)
def answers_to_iso_code?(search_code)
return true if search_code == iso_code

pc = parent_country
Expand Down Expand Up @@ -616,9 +616,9 @@ def passes_country_zip_regexp?(value:, partial_match: false)
#
# Returns the Region in which the zip belongs based on the prefix, or `nil` if no match is found.
def search_prefixes_by_normalized_zip(prefixes:, zip:, allow_partial_zip: false)
return nil if Worldwide::Util.blank?(prefixes)
return nil if Worldwide::Util.blank?(zip)
return nil unless allow_partial_zip || passes_country_zip_regexp?(value: zip)
return if Worldwide::Util.blank?(prefixes)
return if Worldwide::Util.blank?(zip)
return unless allow_partial_zip || passes_country_zip_regexp?(value: zip)

stripped = Zip.strip_optional_country_prefix(country_code: iso_code, zip: zip)

Expand Down
1 change: 1 addition & 0 deletions lib/worldwide/regions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Regions

class << self
extend Forwardable

def_delegators :instance, :all, :region_by_cldr_code, :region
end

Expand Down
2 changes: 0 additions & 2 deletions lib/worldwide/regions_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@ def load_territory(filename)
spec = YAML.safe_load_file(filename)
code = spec["code"]

loaded_regions = []

region = Region.new(
alpha_three: country_codes.dig(code, "alpha3"),
continent: false,
Expand Down
6 changes: 3 additions & 3 deletions lib/worldwide/zip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def gb_style?(country_code:)
# @param min_confidence [Integer] The minimum confidence level (between 0-100) that is accepted from a suggestion (optional)
# @return [Region] which is a "country" if we have a suggestion, or `nil` if we do not.
def find_country(country_code: nil, zip:, min_confidence: 0)
return nil unless Util.present?(zip)
return unless Util.present?(zip)

country = Worldwide.region(code: country_code) unless country_code.nil?
return country if country&.valid_zip?(zip)
Expand All @@ -62,7 +62,7 @@ def find_country(country_code: nil, zip:, min_confidence: 0)
return suggestion unless suggestion.nil? || confidence.nil? || confidence < min_confidence

# If our postal code is wholly numeric, we can't make an intelligent suggestion without an alleged country.
return nil unless adjusted_zip.match?(/[A-Z]/)
return unless adjusted_zip.match?(/[A-Z]/)

# Try a broader-ranging match without considering the alleged country
# We'll see if we have only a single suggestion and, if so, return it.
Expand Down Expand Up @@ -95,7 +95,7 @@ def normalize(country_code:, zip:, allow_autofill: true, strip_extraneous_charac
return autofill if Util.present?(autofill)
end

return nil if zip.nil?
return if zip.nil?

# Convert to uppercase
# Convert numeric and romaji full-width to half-width
Expand Down
2 changes: 1 addition & 1 deletion rake/cldr/cleaner.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true

require "fileutils"
require "worldwide/paths"
Expand Down
Loading
Loading