aboutsummaryrefslogblamecommitdiffstats
path: root/README.md
blob: c1a4a8217a6619dfcf77eeb264f03c96753ac46e (plain) (tree)
1
2
3
4
5
6
7


                           



                                                                                                                                                        











                                                                                                                                                                
                                   


















                                                                                        



                                                     
 



                                                























                                                                     
Search postcodes for Norway
===========================

[![Gem Version](https://badge.fury.io/rb/postcodes-norway.svg)](http://badge.fury.io/rb/postcodes-norway)
[![Code Climate](https://codeclimate.com/github/snake66/postcodes-norway/badges/gpa.svg)](https://codeclimate.com/github/snake66/postcodes-norway)
[![Test Coverage](https://codeclimate.com/github/snake66/postcodes-norway/badges/coverage.svg)](https://codeclimate.com/github/snake66/postcodes-norway)

This gem is a simple interface to the Norwegian postcode database published by Bring. It allows you to search for and retreive entries in the postcode database.

A rake task is included to fetch the actual postcode data as published by Bring.


Installation
------------

In your Gemfile, add the following:

    gem 'postcodes-norway'

Then run `bundle install` as usual.

Fetch the data:

    rake postcodes:fetch[output_dir]

A file named "Postnummerregister_ansi.txt" will be placed in the specified `output_dir`.


Usage
-----

Initialize the library:

    require 'postcodes-norway'

    PostCodes.load('output_dir/Postnummerregister_ansi.txt')

Query for some postcodes:

    p1 = PostCodes.search(1326)
    puts p1.city                 # => "LYSAKER"
    puts p1.municipality_name    # => "BÆRUM"
    puts p1.county               # => [2, "AKERSHUS"]

    p2 = PostCodes.search('0666')
    puts p2.city                # => "OSLO"
    puts p2.municipality_name   # => "OSLO"
    puts p2.county              # => [3, "OSLO"]


Contributing
------------

Feel free to send suggestions or pull requests.

License
-------

Copyright (C) 2015  Harald Eilertsen

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.