244 shaares
118 liens privés
118 liens privés
Simple to use :
- Read csv using headers to name symbols
- Parse table like each row is a hash where each column header is a symbol's name.
- do whatever you want with value.
Example :
require 'smarter_csv'
# Class CodePostaux
class CodePostaux
attr_accessor :csv_file_path, :cp_hash
def initialize(csv_file_path)
@csv_file_path = csv_file_path
@cp_hash = Hash.new
end
def read_csv
SmarterCSV.process(@csv_file_path, {col_sep: ';'})
end
end
output = File.open('./test/minitest/fixtures/code_postaux_provisioning.rb', 'w')
codes_postaux.each do |value|
output.write("PostCode.create(code: '#{value[:code_postal]} #{value[:nom_commune]}')\n")
end
output.close