class Geocoder::Result::SmartyStreets

def address

def address
  parts =
    if international_endpoint?
      (1..12).map { |i| @data["address#{i}"] }
    else
      [
        delivery_line_1,
        delivery_line_2,
        last_line
      ]
    end
  parts.select{ |i| i.to_s != "" }.join(" ")
end

def city

def city
  if international_endpoint?
    components['locality']
  elsif zipcode_endpoint?
    city_states.first['city']
  else
    components['city_name']
  end
end

def coordinates

def coordinates
  result = %w(latitude longitude).map do |i|
    zipcode_endpoint? ? zipcodes.first[i] : metadata[i]
  end
  if result.compact.empty?
    nil
  else
    result
  end
end

def country

def country
  international_endpoint? ?
    components['country_iso_3'] :
    "United States"
end

def country_code

def country_code
  international_endpoint? ?
    components['country_iso_3'] :
    "US"
end

def fips

def fips
  zipcode_endpoint? ?
    zipcodes.first['county_fips'] :
    metadata['county_fips']
end

def international_endpoint?

def international_endpoint?
  !@data['address1'].nil?
end

def state

def state
  if international_endpoint?
    components['administrative_area']
  elsif zipcode_endpoint?
    city_states.first['state']
  else
    components['state_abbreviation']
  end
end

def state_code

def state_code
  if international_endpoint?
    components['administrative_area']
  elsif zipcode_endpoint?
    city_states.first['state_abbreviation']
  else
    components['state_abbreviation']
  end
end

def street

def street
  international_endpoint? ?
    components['thoroughfare_name'] :
    components['street_name']
end

def zip4

def zip4
  components['plus4_code']
end

def zipcode

def zipcode
  if international_endpoint?
    components['postal_code']
  elsif zipcode_endpoint?
    zipcodes.first['zipcode']
  else
    components['zipcode']
  end
end

def zipcode_endpoint?

def zipcode_endpoint?
  zipcodes.any?
end