Class: Chicago::ETL::Transformations::UkPostCodeField
- Inherits:
-
Object
- Object
- Chicago::ETL::Transformations::UkPostCodeField
- Defined in:
- lib/chicago/etl/transformations/uk_post_code_field.rb
Constant Summary collapse
- MATCH =
/\A([A-Z][A-Z]?[0-9][0-9A-Z]?)(?:([0-9][A-Z]{2}))?\Z/
Instance Method Summary collapse
-
#normalize(raw_post_code) ⇒ Object
Returns cleaned, formatted data about a UK Post Code.
Instance Method Details
#normalize(raw_post_code) ⇒ Object
Returns cleaned, formatted data about a UK Post Code.
Example:
UkPostCodeField.new.normalize(" SW !2 4 GH")
# => { :post_code => "SW12 4GH",
:outcode => "SW12",
:incode => "4GH" }
Partial postcodes will be returned without the incode. BFPO postcodes are supported, but have no incode or outcode. Postcodes that do not follow the format will be returned as is, with an invalid key set.
22 23 24 25 |
# File 'lib/chicago/etl/transformations/uk_post_code_field.rb', line 22 def normalize(raw_post_code) reformat(clean(raw_post_code)) || {:post_code => raw_post_code, :invalid => true} end |