module FFaker::AddressUS

Constants

CONTINENTAL_STATE
CONTINENTAL_STATE_ABBR
ZIP_FORMATS

Public Instance Methods

continental_state() click to toggle source
# File lib/ffaker/address_us.rb, line 34
def continental_state
  fetch_sample(CONTINENTAL_STATE)
end
continental_state_abbr() click to toggle source
# File lib/ffaker/address_us.rb, line 38
def continental_state_abbr
  fetch_sample(CONTINENTAL_STATE_ABBR)
end
state() click to toggle source
# File lib/ffaker/address_us.rb, line 18
def state
  fetch_sample(STATE)
end
state_abbr(st_name = nil) click to toggle source
# File lib/ffaker/address_us.rb, line 22
def state_abbr(st_name = nil)
  return find_abbr(state) unless st_name

  st_name = capitalize_all_words(st_name)
  check_state_existence(st_name)
  find_abbr(st_name)
end
state_and_territories_abbr() click to toggle source
# File lib/ffaker/address_us.rb, line 30
def state_and_territories_abbr
  fetch_sample(STATE_AND_TERRITORIES_ABBR)
end
zip_code() click to toggle source
# File lib/ffaker/address_us.rb, line 14
def zip_code
  FFaker.numerify(fetch_sample(ZIP_FORMATS))
end

Private Instance Methods

capitalize_all_words(string) click to toggle source
# File lib/ffaker/address_us.rb, line 54
def capitalize_all_words(string)
  string.split.map(&:capitalize).join(' ')
end
check_state_existence(state_name) click to toggle source
# File lib/ffaker/address_us.rb, line 44
def check_state_existence(state_name)
  return if STATE.include?(state_name)

  raise ArgumentError, "Unexpected state name: '#{state_name}'"
end
find_abbr(state) click to toggle source
# File lib/ffaker/address_us.rb, line 50
def find_abbr(state)
  STATE_ABBR[STATE.index(state)]
end