Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/luismiramirez/spain_zip_codes
Get Spain provinces and locations with zip codes and reverse
https://github.com/luismiramirez/spain_zip_codes
Last synced: 3 months ago
JSON representation
Get Spain provinces and locations with zip codes and reverse
- Host: GitHub
- URL: https://github.com/luismiramirez/spain_zip_codes
- Owner: luismiramirez
- License: mit
- Created: 2014-10-15T10:27:28.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2014-11-28T08:42:15.000Z (over 9 years ago)
- Last Synced: 2024-01-17T18:49:59.646Z (5 months ago)
- Language: Ruby
- Homepage:
- Size: 382 KB
- Stars: 5
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Lists
- awesome-world - spain_zip_codes gem :octocat: - get spanish provinces and locations with zip codes and reverse (Europe / Spain / España (es))
README
# SpainZipCodes
[![Build Status](https://travis-ci.org/luismiramirez/spain_zip_codes.svg?branch=master)](https://travis-ci.org/luismiramirez/spain_zip_codes)
[![Code Climate](https://codeclimate.com/github/luismiramirez/spain_zip_codes/badges/gpa.svg)](https://codeclimate.com/github/luismiramirez/spain_zip_codes)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!
## Installation
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:
```ruby
require 'spain_zip_codes'
```
## Usage### Provinces
#### To get a province name from a zip code do:
```ruby
SpainZipCodes.zip_to_province(zip)> SpainZipCodes.zip_to_province('28001')
=> 'Madrid'
```#### To get a zip code prefix for a province do:
```ruby
SpainZipCodes.province_to_zip(province)> SpainZipCodes.province_to_zip('Madrid')
=> '28'
```### Locations
#### To get a location name from a zip code do:
```ruby
SpainZipCodes.zip_to_location(zip)> SpainZipCodes.zip_to_location('28922')
=> 'Alcorcón'
```#### To get the zip codes from a location name do:
```ruby
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')
=> []
```#### To get the location slug from a zip code do:
```ruby
SpainZipCodes.zip_to_location_slug(zip)> SpainZipCodes.zip_to_location_slug('28750')
=> 'san-agustin-de-guadalix'
```#### To get the zip codes from a location slug:
```ruby
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``
## Contributing
1. Fork it ( https://github.com/luismiramirez/spain_zip_codes/fork )
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 a new Pull Request