Class: PostCodes::PostCode
- Inherits:
-
Object
- Object
- PostCodes::PostCode
- Defined in:
- lib/postcodes-norway.rb
Overview
Class for holding postcode data
Instance Attribute Summary collapse
-
#cat ⇒ Object
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.
-
#city ⇒ Object
readonly
Name of city.
-
#municipality ⇒ Object
readonly
Four digit municipality (‘kommune’) id.
-
#municipality_name ⇒ Object
readonly
Name of municipality (‘kommune’).
-
#postcode ⇒ Object
readonly
Four digit post code.
Instance Method Summary collapse
-
#county ⇒ Object
Return the County (‘kommune’) from the postcode data.
-
#initialize(postcode, city, muni, muni_name, cat) ⇒ PostCode
constructor
Create a new post code.
-
#to_s ⇒ Object
Output postcode data in the same format as in the original postcode database.
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
#cat ⇒ Object (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 |
#city ⇒ Object (readonly)
Name of city
38 39 40 |
# File 'lib/postcodes-norway.rb', line 38 def city @city end |
#municipality ⇒ Object (readonly)
Four digit municipality (‘kommune’) id
41 42 43 |
# File 'lib/postcodes-norway.rb', line 41 def municipality @municipality end |
#municipality_name ⇒ Object (readonly)
Name of municipality (‘kommune’)
44 45 46 |
# File 'lib/postcodes-norway.rb', line 44 def municipality_name @municipality_name end |
#postcode ⇒ Object (readonly)
Four digit post code
35 36 37 |
# File 'lib/postcodes-norway.rb', line 35 def postcode @postcode end |
Instance Method Details
#county ⇒ Object
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_s ⇒ Object
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 |