Skip to content

Commit

Permalink
write_csv_line doesn't have to be a prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
myf committed Sep 3, 2014
1 parent b810133 commit afcf755
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/csv_split.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ var Splitter = function(input_stream, output_dir, group_by) {
this.group_sequence = null;
};

Splitter.prototype.write_csv_line = function(arr) {
//adding quotes
var quoted_arr = arr.map(function(item) {
return '\"' + item + '\"';
});
return quoted_arr.toString() + '\n';
};


Splitter.prototype.split = function() {
var self = this;
Expand All @@ -37,12 +29,12 @@ Splitter.prototype.drain = function(data) {
var name = data.name;
var outfile = path.resolve(this.output_dir, name + ".csv");
if (this.write_streams[name]) {
this.write_streams[name].write(this.write_csv_line(data.data));
this.write_streams[name].write(write_csv_line(data.data));
} else {
var ws = fs.createWriteStream(outfile);
this.write_streams[name] = ws;
ws.write(this.write_csv_line(this.header));
ws.write(this.write_csv_line(data.data));
ws.write(write_csv_line(this.header));
ws.write(write_csv_line(data.data));
}
};

Expand All @@ -68,6 +60,14 @@ Splitter.prototype.run = function() {
});
};

var write_csv_line = function(arr) {
//adding quotes
var quoted_arr = arr.map(function(item) {
return '\"' + item + '\"';
});
return quoted_arr.toString() + '\n';
};

var clean_name = function(file_name) {
// file_name cannot have '/', '\' in it
// convert them into underscore
Expand Down

0 comments on commit afcf755

Please sign in to comment.