-
Notifications
You must be signed in to change notification settings - Fork 0
/
tableReader.js
38 lines (33 loc) · 1.01 KB
/
tableReader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var fs = require('fs');
var tableReader = (function() {
var attribute = 'none';
var attributeAdjustments = [];
var firstRow = true;
var readTableForAttribute = function(stats, filename) {
var firstRow = true;
var csvFile = fs.readFileSync(filename,'utf8');
csvFile.split('\n').forEach(function (line) {
var line = line.split(',');
if (firstRow) {
attribute = line[0];
attributeAdjustments = line.slice(1);
firstRow = false;
} else {
doTableRowWork(stats, line, attribute, attributeAdjustments);
}
});
return stats;
}
var doTableRowWork = function(stats, line, attribute, attributeAdjustments) {
if (stats[attribute] == line[0]) {
for (var i =0;i<attributeAdjustments.length;i++) {
stats[attributeAdjustments[i].trim()] = line[i+1].trim();
}
}
return stats;
}
return {
readTableForAttribute: readTableForAttribute,
};
})();
module.exports = tableReader;