Class: PostCodes::PostCode

Inherits:
Object
  • Object
show all
Defined in:
lib/postcodes-norway.rb

Overview

Class for holding postcode data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(postcode, city, muni, muni_name, cat) ⇒ PostCode

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



57
58
59
# 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

Instance Attribute Details

#catObject (readonly)

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



53
54
55
# File 'lib/postcodes-norway.rb', line 53

def cat
  @cat
end

#cityObject (readonly)

Name of city



38
39
40
# File 'lib/postcodes-norway.rb', line 38

def city
  @city
end

#municipalityObject (readonly)

Four digit municipality (‘kommune’) id



41
42
43
# File 'lib/postcodes-norway.rb', line 41

def municipality
  @municipality
end

#municipality_nameObject (readonly)

Name of municipality (‘kommune’)



44
45
46
# File 'lib/postcodes-norway.rb', line 44

def municipality_name
  @municipality_name
end

#postcodeObject (readonly)

Four digit post code



35
36
37
# File 'lib/postcodes-norway.rb', line 35

def postcode
  @postcode
end

Instance Method Details

#countyObject

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



63
64
65
66
# File 'lib/postcodes-norway.rb', line 63

def county
  code = @municipality[0..1].to_i
  [code, PostCodes.county(code)]
end

#to_sObject

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



69
70
71
# File 'lib/postcodes-norway.rb', line 69

def to_s
  [@postcode, @city, @municipality, @municipality_name, @cat].join("\t")
end