lib/worldwide/zip.rb in worldwide-0.6.0 vs lib/worldwide/zip.rb in worldwide-0.6.1

- old
+ new

@@ -48,11 +48,11 @@ # @param country_code [String] The country code that the user thought this postal code was for (optional) # @param zip [String] The postal code that the user entered (required) # @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 zip.present? + return nil unless Util.present?(zip) country = Worldwide.region(code: country_code) unless country_code.nil? return country if country&.valid_zip?(zip) adjusted_zip = zip.strip.upcase @@ -66,12 +66,12 @@ # 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. # In cases where there's more than one possible match, we'll return nil. suggestions = find_country_using_zip_alone(adjusted_zip) - suggestion = suggestions.first[0] unless suggestions.blank? - confidence = suggestions.first[1] unless suggestions.blank? + suggestion = suggestions.first[0] unless Util.blank?(suggestions) + confidence = suggestions.first[1] unless Util.blank?(suggestions) return suggestion if suggestions.length == 1 && confidence && confidence >= min_confidence nil end @@ -88,11 +88,11 @@ country = Worldwide.region(code: country_code) return zip if country.nil? || NORMALIZATION_DISABLED_COUNTRIES.include?(country.iso_code) if allow_autofill autofill = country.autofill_zip - return autofill if autofill.present? + return autofill if Util.present?(autofill) end return nil if zip.nil? # Convert to uppercase @@ -161,11 +161,11 @@ normalize(country_code: country_code, zip: zip)&.split(" ")&.first end def strip_optional_country_prefix(country_code:, zip:) - return zip if zip.blank? + return zip if Util.blank?(zip) unless OPTIONAL_PREFIX_COUNTRIES.include?(country_code&.to_sym) return zip end @@ -602,11 +602,11 @@ def replace_letters_and_numbers_for_alphanumeric(country_code:, zip:) unless ALPHNUMERIC_POSTAL_CODE_FORMATS.include?(country_code.to_sym) return zip end - return zip if zip.blank? + return zip if Util.blank?(zip) autocorrected_zips = [] input = zip modified_input = input.dup @@ -725,11 +725,11 @@ outcode + (incode || "") end def normalize_for_bd(zip:) - return zip if zip.blank? + return zip if Util.blank?(zip) m = zip.match(/^(GPO:?|DHAKA)(\d{4})$/) if m.nil? zip else @@ -832,13 +832,13 @@ # - codes ending in four zeroes often drop one of them, "4000" instead of "40000" def normalize_for_lk(zip:) return zip if zip.nil? m = zip.match(/^0?0?0?0?([1-9])0?0?$/) - return "00#{m[1]}00" if m.present? + return "00#{m[1]}00" if Util.present?(m) m = zip.match(/^0?0?1([1-9])0?0?$/) - return "01#{m[1]}00" if m.present? + return "01#{m[1]}00" if Util.present?(m) if zip.match?(/^[1-9][0-9]00$/) "#{zip}0" else zip