Sha256: 1a6227abae692d5d6a4b2bc24e15bd0137f03f3eace1258e2e238d060846a153
Contents?: true
Size: 800 Bytes
Versions: 16
Compression:
Stored size: 800 Bytes
Contents
#!/usr/bin/env ruby require 'csv' def columns_changed?(previous_row, row, change_columns) changed = false change_columns.each do |column| changed ||= previous_row[column] != row[column] end changed end def file_name_from_changed_columns(row, change_columns) change_columns.map { |column| row[column] }.join("_") + ".csv" end change_columns = ARGV[0].split(/,/).map(&:to_i) input_file = ARGV[1] previous_row = output_csv = nil CSV.foreach(input_file) do |row| if previous_row.nil? || (previous_row && columns_changed?(previous_row, row, change_columns)) output_csv.close if output_csv output_file_name = file_name_from_changed_columns(row, change_columns) output_csv = CSV.open(output_file_name, "w") end output_csv << row previous_row = row end output_csv.close
Version data entries
16 entries across 16 versions & 1 rubygems