Skip to content

rinsed-org/zip-codes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ZipCodes

Retrieve city, state, and time zone for a given ZIP code for those times when API's just aren’t doable 🎉

Updating ZipCodes DB

  1. Download the latest US.yml from https://github.com/monterail/zip-codes/tree/master/lib/data
  2. In a rails console:
zips = YAML.safe_load_file("/absolute/path/to/US.yml", permitted_classes: [Symbol]).to_h
zips.each do |zip, z|
  puts "#{zip},#{z[:state_code]},#{z[:state_name]},#{z[:city]},#{z[:time_zone]}"
end; nil
  1. Update the existing US.csv file with the printed contents

This isn't the cleanest approach, ideally we should take the time to put this in a script to streamline updates.

Installation

Using bundler, add to the Gemfile:

gem 'zip-codes'

Or standalone:

$ gem install zip-codes

Standard Usage

ZipCodes.lookup('US', '30301')
# => {:state_code=>"GA", :state_name=>"Georgia", :city=>"Atlanta", :time_zone=>"America/New_York"}

# Case insensitive
ZipCodes.lookup('uS', '30301')
# => {:state_code=>"GA", :state_name=>"Georgia", :city=>"Atlanta", :time_zone=>"America/New_York"}

# Symbols work too
ZipCodes.lookup(:US, '30301')
# => {:state_code=>"GA", :state_name=>"Georgia", :city=>"Atlanta", :time_zone=>"America/New_York"}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages