Skip to content

Instantly share code, notes, and snippets.

@Floppy
Created January 14, 2015 13:58
Show Gist options
  • Save Floppy/ac87f1e53142cea445a1 to your computer and use it in GitHub Desktop.
Save Floppy/ac87f1e53142cea445a1 to your computer and use it in GitHub Desktop.
ETL port
@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