module PostCodes

Constants

Counties

Correspond to the Norwegian ‘Fylke’

Public Class Methods

county(index) click to toggle source

Return the county by number.

Takes a number between 1 and 23 as input. This corresponds to the first two digits in the municipality number.

The county name as a string is returned.

# File lib/postcodes-norway.rb, line 112
def county(index)
  return nil unless index > 0 && index <= Counties.size
  Counties[index - 1]
end
load(file) click to toggle source

Load the postcode data into memory.

file is a file name or IO object to read the data from.

# File lib/postcodes-norway.rb, line 79
def load(file)
  @postcodes = []
  if file.is_a?(String)
    f = File.open(file, :encoding => Encoding::ISO_8859_15)
  else
    f = file
  end

  f.each_line do |l|
    a = l.chomp().split("\t").map{|s| s.encode(Encoding::UTF_8)}
    @postcodes << PostCode.new(*a)
  end
end