Class: Posten
Overview
Norwegian zip codes
Constant Summary
Constants included from Difi
Class Method Summary collapse
- .data ⇒ Object
-
.get ⇒ Object
Get the zip code database.
- .lines ⇒ Object
- .parse ⇒ Object
- .response ⇒ Object
-
.url ⇒ Object
The URL to the geo-tagged zip code database by Erik Bolstad.
-
.zipcodes(*county) ⇒ Object
Return zip codes for the given counties.
Methods included from Difi
conn, dataset, fields, get, json, response, search, url
Class Method Details
.data ⇒ Object
26 27 28 |
# File 'lib/posten.rb', line 26 def self.data @@data ||= response.body end |
.get ⇒ Object
Get the zip code database
13 14 15 |
# File 'lib/posten.rb', line 13 def self.get conn.get url end |
.lines ⇒ Object
30 31 32 |
# File 'lib/posten.rb', line 30 def self.lines @@lines ||= data.gsub(/\t/, ',').split("\n") end |
.parse ⇒ Object
34 35 36 |
# File 'lib/posten.rb', line 34 def self.parse @@all_lines ||= lines.collect {|l| l.parse_csv } end |
.response ⇒ Object
17 18 19 |
# File 'lib/posten.rb', line 17 def self.response @@response ||= get end |
.url ⇒ Object
The URL to the geo-tagged zip code database by Erik Bolstad
8 9 10 |
# File 'lib/posten.rb', line 8 def self.url @@url = "http://www.erikbolstad.no/postnummer-koordinatar/txt/postnummer.csv" end |
.zipcodes(*county) ⇒ Object
Return zip codes for the given counties
22 23 24 |
# File 'lib/posten.rb', line 22 def self.zipcodes(*county) @@result = parse.collect {|l| l if county.include?(l[8]) }.compact end |