File size: 1,173 Bytes
ae4627d | 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | /**
* Internal dependencies.
*/
var Formatter = require('../formatter');
/**
* Rank formatter.
*
* @constructor
*/
var Rank = Formatter.extend();
/**
* Run the formatter.
*
* @api public
*/
Rank.prototype.run = function() {
var rows = [];
var longestScore = 0;
var longestSignature = 0;
this.sources.forEach(function(source) {
source.eachContext(function(context) {
var score = context.score();
var signature = context.signature();
if (score < this.options.min) return;
score = this.toFixed(score);
longestSignature = Math.max(signature.length, longestSignature);
longestScore = Math.max(score.length, longestScore);
rows.push([score, signature, source.path + ':' + context.location()]);
}, this);
}, this);
rows.sort(function(a, b) {
var first = +a[0];
var second = +b[0];
if (first > second) return -1;
if (first < second) return 1;
return 0;
}).forEach(function(row) {
this.print(
this.ljust(row[0], longestScore) + ' ' +
this.ljust(row[1], longestSignature) + ' ' +
row[2]);
}, this);
};
/**
* Primary export.
*/
module.exports = Rank;
|