Created
January 14, 2015 13:58
-
-
Save Floppy/ac87f1e53142cea445a1 to your computer and use it in GitHub Desktop.
ETL port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@output = [] | |
companyreader.each_with_index do |row, row_index| | |
# Check the line has a postcode | |
next if row['RegAddress.PostCode'].blank? | |
postcode = Postcode(row['RegAddress.PostCode'],db) | |
next unless postcode.current? | |
lines = [row['RegAddress.AddressLine1'], row['RegAddress.AddressLine2'], row['RegAddress.PostTown'], row['RegAddress.County']] | |
# Parse all the things | |
a.setAddress(lines,postcode) | |
next if a.getTown().blank? | |
a.getStreet() | |
a.getAons() | |
# Build output structure | |
address = { | |
'address' => a.elements, | |
'provenance' = { | |
'executed_at' => datetime.datetime.today().strftime("%Y-%m-%dT%H:%M:%SZ"), | |
'url' => "http://download.companieshouse.gov.uk/en_output.html", | |
'filename' => file, | |
'record_no' => row_index.to_s | |
} | |
} | |
address['address']['postcode'] = { | |
'name' => pc.getPostcode("S"), | |
'geometry' => { | |
'type' => 'Point', | |
'coordinates' => [pc.centroid[1], pc.centroid[0]] | |
} | |
} | |
@output.append(address) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment