Last active
July 11, 2016 01:16
-
-
Save ysksn/7ba150c0e705b284620aefe8ccda90c9 to your computer and use it in GitHub Desktop.
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
require 'csv' | |
csv_file = File.new('/Users/marketing-imac1/Desktop/tmp.csv') | |
json_file = File.open('/Users/marketing-imac1/Desktop/areas.json', 'w') | |
csv = CSV.open(csv_file, 'r').to_a | |
str = '' | |
last_index = csv.length - 1 | |
block = lambda do |row, i| | |
closer = i == last_index ? "]" : "]," | |
str += ' [' + [('"' + row[0]) + '"', row[1], row[2], row[3]].join(', ') + closer + "\n" | |
end | |
csv.each_with_index(&block) | |
str = "var areas =\n" \ | |
str \ | |
'];' | |
File.open(json_file, 'w') { |file| file.puts str } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment