-
Notifications
You must be signed in to change notification settings - Fork 2
/
message.js
48 lines (40 loc) · 1.32 KB
/
message.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
39
40
41
42
43
44
45
46
47
48
'use strict';
const chalk = require('chalk');
const constants = require('./constants');
const wtf = chalk.bgRed(chalk.blue('W') + chalk.yellow('T') + chalk.green('F'));
const typeMessages = new Map([
[constants.IDENTICAL_FILE, `are ${chalk.red('IDENTICAL')} ${wtf} !!! \n`],
[constants.INTER_FILE_DUPLICATE, 'repeat the following: \n'],
[constants.INTRA_FILE_DUPLICATE, 'repeats the following within the file: \n']
]);
class Message {
constructor (docs, type, hashes, content = '') {
this.docs = docs;
this.type = type;
this.hashes = [hashes];
this.content = [content];
}
toPlainEnglish () {
return this._makeMessageTitle() + this._makeMessageContent();
}
_makeMessageTitle () {
let msg = '';
if (this.docs.length === 2) {
msg += `${chalk.yellow(this.docs[0])} and ${chalk.yellow(this.docs[1])} `;
} else {
this.docs.forEach((doc, i) => {
let lastDoc = i === (this.docs.length + 1);
let docName = chalk.yellow(this.docs[i]);
lastDoc ? msg += `and ${docName}` : msg += `${docName}, `;
});
}
msg += typeMessages.get(this.type);
return msg;
}
_makeMessageContent () {
return this.content.map((content, ind) => {
if (content) { return `${ind + 1}.)\n\t ${chalk.red(content)} \n`; }
}).join('');
}
}
module.exports = Message;