From afcf7551b8fbf86a271eb2a629897c326b988465 Mon Sep 17 00:00:00 2001 From: Myf Ma Date: Wed, 3 Sep 2014 14:39:19 -0400 Subject: [PATCH] write_csv_line doesn't have to be a prototype --- lib/csv_split.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/csv_split.js b/lib/csv_split.js index 75ff87d..a25c86d 100644 --- a/lib/csv_split.js +++ b/lib/csv_split.js @@ -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; @@ -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)); } }; @@ -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