Skip to content

Instantly share code, notes, and snippets.

@universal
Forked from anonymous/example.rb
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save universal/1a72a67bbc176173bbec to your computer and use it in GitHub Desktop.

Select an option

Save universal/1a72a67bbc176173bbec to your computer and use it in GitHub Desktop.
task :postcode_import => :environment do
puts "\n\n Importing PostCodes"
lat_long_res = []
CSV.foreach "lib/data/example.csv" do |row|
if row[0].include? " "
postcode = row[0]
else
postcode = row[0][0..3] + " " + row[4..-1]
end
easting = row[1].to_i
northing = row[2].to_i
en_to_ll = Silva::Location.from(:en, :easting => easting, :northing => northing).to(:wgs84)
lat_long_res << en_to_ll
end
lat_long_res.flatten
lat_long_res.each { |lat, long| Postcode.first_or_create(lat: lat, long: long)}
end
CB114ZX 553692 238424
CB2 0AA 546031 254843
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment