-
Notifications
You must be signed in to change notification settings - Fork 1
/
season.js
50 lines (42 loc) · 1.19 KB
/
season.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
class Season {
constructor(id) {
this.id = id;
}
static fromJSON(jsonObject) {
return new Season(jsonObject.id);
}
static current(date = new Date()) {
const month = date.getMonth() + 1;
return new Season(`${date.getFullYear()}-${month.length === 2 ? month : `0${month}`}`);
}
toString() {
return this.id;
}
}
class PlayerRanking {
constructor(tag, name, rank, previousRank, expLevel, score, isTrophies, isElo) {
this.tag = tag;
this.name = name;
this.rank = rank;
this.previousRank = previousRank;
this.expLevel = expLevel;
this.score = score;
this.isTrophies = isTrophies;
this.isElo = isElo;
}
static fromJSON(jsonObject) {
return new PlayerRanking(
jsonObject.tag,
jsonObject.name,
jsonObject.rank,
jsonObject.previousRank || jsonObject.rank,
jsonObject.expLevel,
jsonObject.eloRating || jsonObject.trophies,
!!jsonObject.trophies,
!!jsonObject.eloRating);
}
toString() {
return this.name;
}
}
module.exports = { Season, PlayerRanking }