8000 GitHub - jefferal1995/postal-codes-search: Gem to search US and CA postal codes
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

jefferal1995/postal-codes-search

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Postal Codes Search Gem Version

Gem to obtain postal codes for US and CA only.

Installation

Add this line to your application's Gemfile:

gem 'postal-codes-search', '~> 1.1'

And then execute:

$ bundle

Or install it yourself as:

$ gem install postal-codes-search

Usage

You can search generally by any keyword like country, county, postal code, state and or city like this

PostalCodesSearch.find('Y1A')
# => [{"country"=>"CA", "postal_code"=>"Y1A", "city"=>"Whitehorse", "state"=>"Yukon", "county"=>nil}]
# This will return an array. If you put an incomplete postal code, it will return the most similar results

You can use more specific search depending on the attribute you want to use

By code

PostalCodesSearch.find_by(code: 'Y1A')
# => [{"country"=>"CA", "postal_code"=>"Y1A", "city"=>"Whitehorse", "state"=>"Yukon", "county"=>nil}]

By country

PostalCodesSearch.find_by(country: 'US').count
# => 41469

By county

PostalCodesSearch.find_by(county: 'Yukon-Koyukuk').first
# => {"country"=>"US", "postal_code"=>99558, "city"=>"Anvik", "state"=>"Alaska", "county"=>"Yukon-Koyukuk (CA)"}

By state

PostalCodesSearch.find_by(state: 'Alaska').count
# => 273

By city

PostalCodesSearch.find_by(city: 'Venetie')
# => [{"country"=>"US", "postal_code"=>99781, "city"=>"Venetie", "state"=>"Alaska", "county"=>"Yukon-Koyukuk (CA)"}]

Using rails, you can load all the values in a initializer

# config/initializers/postal_codes.rb
PostalCodesSearch.load unless Rails.env.development?

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

Gem to search US and CA postal codes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0