Permalink
Browse files

Added example.js

  • Loading branch information...
amaurer committed Dec 14, 2012
1 parent bf8a6b3 commit 92f6fde50102afb58500c3251c147c20aee7ff22
Showing with 29 additions and 1 deletion.
  1. +26 −0 example.js
  2. +3 −1 log-massage.js
View
@@ -0,0 +1,26 @@
+var fs = require("fs");
+var LogMassage = require("./log-massage.js");
+
+var logFilePath = "mylog.log";
+
+
+fs.readFile(logFilePath, function(e, data){
+
+ var count = 0;
+ var lm = new LogMassage(data)
+ .toDate(2, 3)
+ .removeRowCells(1, 4)
+ .filterBetween(
+ new Date("12/03/12"),
+ new Date("12/04/12"),
+ 2
+ )
+ .eachRow(function(rowIndex, row){
+ count++;
+ return true;
+ });
+
+ console.log(lm);
+ console.log(count);
+
+});
View
@@ -35,14 +35,16 @@ LogMassage.prototype.toArrays = function(stringData){
var logResults = [];
var rows = stringData.toString().split(this.rowDelimiter);
var cells = [];
+ var replaceQuotes = /"/g;
+ var replaceCarriageReturns = /\r/g;
for (i = 1, len = rows.length; i<len; i++) {
x = rows[i];
if(x === "" || x.length === 0) continue;
cells = x.split(this.cellDelimiter);
tmp = [];
for (ii = 0, lenn = cells.length; ii<lenn; ii++) {
tmp.push(
- cells[ii].replace(/"/g, "").replace(/\r/g, "")
+ cells[ii].replace(replaceQuotes, "").replace(replaceCarriageReturns, "")
);
};
logResults.push(tmp);

0 comments on commit 92f6fde

Please sign in to comment.