-
Notifications
You must be signed in to change notification settings - Fork 1
/
printer.js
68 lines (57 loc) · 1.57 KB
/
printer.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var Table = require('cli-table');
// Constants
var HDELIMITER = '\t\t\t';
var DELIMITER = '\t\t';
exports.games = function (games) {
if (games.length > 0) {
var table = new Table({
head: ['Date', 'Home Team', 'Away Team', 'Final Score'],
colWidths: [20, 20, 20, 20],
});
games.forEach(function (game) {
table.push([game.date.toDateString(), game.homeTeam, game.awayTeam,
game.score.fullTime.home + ' - ' + game.score.fullTime.away]);
});
console.log(table.toString());
} else {
console.log('--------------------');
console.log('No games match the criteria');
console.log('--------------------');
}
};
exports.leagueTable = function (teams, date) {
console.log('League table as on ', date);
var table = new Table({
head: ['Position', 'Team', 'Played', 'Won', 'Drawn', 'Lost', 'G Scored', 'G Conceded', 'G Diff', 'Points'],
colWidths: [10, 20, 10, 10, 10, 10, 10, 10, 10, 10],
});
var count = 0;
teams.forEach(function (team) {
table.push([
count += 1,
team.name,
team.games.played,
team.games.won,
team.games.drawn,
team.games.lost,
team.goals.scored,
team.goals.conceded,
team.goals.diff,
team.games.points
]);
});
console.log(table.toString());
};
exports.teams = function (teams) {
var table = new Table({
head: ['Team', 'Times Played in Premier League since 2000'],
colWidths: [20, 45],
});
teams.forEach(function (team) {
table.push([
team._id,
team.count,
]);
});
console.log(table.toString());
};