With SpainZipCodes you can obtain Spain locations and provinces using a zip code and you can obtain zip codes for provinces and locations using their names!
Add this line to your application's Gemfile:
gem 'spain_zip_codes'
And then execute:
$ bundle
Or install it yourself as:
$ gem install spain_zip_codes
Require the gem:
require 'spain_zip_codes'
SpainZipCodes.zip_to_province(zip)
> SpainZipCodes.zip_to_province('28001')
=> 'Madrid'
SpainZipCodes.province_to_zip(province)
> SpainZipCodes.province_to_zip('Madrid')
=> '28'
SpainZipCodes.zip_to_location(zip)
> SpainZipCodes.zip_to_location('28922')
=> 'Alcorcón'
SpainZipCodes.location_to_zip(location)
> SpainZipCodes.location_to_zip('Alcorcón')
=> ['28920', '28921', '28922', '28923', '28924', '28925']
# A not found location will return an empty array
> SpainZipCodes.location_to_zip('Gallifrey')
=> []
SpainZipCodes.zip_to_location_slug(zip)
> SpainZipCodes.zip_to_location_slug('28750')
=> 'san-agustin-de-guadalix'
SpainZipCodes.location_slug_to_zip(location_slug)
> SpainZipCodes.location_slug_to_zip('alcorcon')
=> ['28920', '28921', '28922', '28923', '28924', '28925']
Note:
Arguments need to be strings.
If you give a function an invalid argument or nothing is found it will always return false
- Fork it ( https://github.com/luismiramirez/spain_zip_codes/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request