Kaynağa Gözat

Ecriture class Formatter

Arthur Brandao 5 yıl önce
ebeveyn
işleme
903081fe8c
2 değiştirilmiş dosya ile 22 ekleme ve 1 silme
  1. 16 1
      src/finder/formatter.js
  2. 6 0
      src/finder/index.js

+ 16 - 1
src/finder/formatter.js

@@ -1,7 +1,22 @@
 const formatter = class Formatter {
 
+    constructor(name, result) {
+        this.name = name;
+        this.result = result.sort(this._alphabeticalSort);
+    }
+
+    toString() {
+        let str = `"${this.name}" has ${this.result.length} coauthors:`;
+        for (const index in this.result) {
+            str += `\n- ${this.result[index]}`;
+        }
+        return str;
+    }
+
     _alphabeticalSort(a, b) {
         return (a > b) ? 1 : -1;
     }
 
-};
+};
+
+module.exports = formatter;

+ 6 - 0
src/finder/index.js

@@ -1,4 +1,5 @@
 const finder = require('./finder').get();
+const formatter = require('./formatter');
 
 module.exports.in = function (path) {
     return finder.from(path);
@@ -7,3 +8,8 @@ module.exports.in = function (path) {
 module.exports.get = function () {
     return finder;
 };
+
+module.exports.toString = function (name, result) {
+    const f = new formatter(name, result);
+    return f.toString();
+};