class Faker::Address

def zip_code(legacy_state_abbreviation = NOT_GIVEN, state_abbreviation: '')

Returns:
  • (String) -

Parameters:
  • state_abbreviation (String) -- an abbreviation for a state where the zip code should be located.
def zip_code(legacy_state_abbreviation = NOT_GIVEN, state_abbreviation: '')
  warn_for_deprecated_arguments do |keywords|
    keywords << :state_abbreviation if legacy_state_abbreviation != NOT_GIVEN
  end
  if state_abbreviation.empty?
    letterified_string = letterify(fetch('address.postcode'))
    return numerify(letterified_string, leading_zero: true)
  end
  # provide a zip code that is valid for the state provided
  # see http://www.fincen.gov/forms/files/us_state_territory_zip_codes.pdf
  bothify(fetch('address.postcode_by_state.' + state_abbreviation))
end