class PostCodes::PostCode

Class for holding postcode data

Attributes

cat[R]

Category

  • ‘G’ = street address

  • ‘P’ = Postboxes

  • ‘B’ = Both street addresses and postboxes

  • ‘S’ = Service addresses

  • ‘K’ = Customer with its own post code

  • ‘F’ = Multiple uses

city[R]

Name of city

municipality[R]

Four digit municipality (‘kommune’) id

municipality_name[R]

Name of municipality (‘kommune’)

postcode[R]

Four digit post code

Public Class Methods

new(postcode, city, muni, muni_name, cat) click to toggle source

Create a new post code. This method should generally not be used by users of the library.

# File lib/postcodes-norway.rb, line 57
def initialize(postcode, city, muni, muni_name, cat)
  @postcode, @city, @municipality, @municipality_name, @cat = postcode, city, muni, muni_name, cat
end

Public Instance Methods

county() click to toggle source

Return the County (‘kommune’) from the postcode data. The returned format is ‘[county_id, county_name]`

# File lib/postcodes-norway.rb, line 63
def county
  code = @municipality[0..1].to_i
  [code, PostCodes.county(code)]
end
to_s() click to toggle source

Output postcode data in the same format as in the original postcode database.

# File lib/postcodes-norway.rb, line 69
def to_s
  [@postcode, @city, @municipality, @municipality_name, @cat].join("\t")
end