2023-04-19 21:54:42 +02:00
|
|
|
export class CpuRepository {
|
2023-04-19 19:57:22 +02:00
|
|
|
#cpuList;
|
|
|
|
|
|
|
|
#currentCPU;
|
|
|
|
#nextCPU;
|
|
|
|
|
|
|
|
async init() {
|
|
|
|
const fetchResult = await fetch("./js/data.json");
|
|
|
|
this.#cpuList = await fetchResult.json();
|
|
|
|
|
|
|
|
this.#currentCPU = this.getRandomCpu();
|
|
|
|
this.#nextCPU = this.getRandomCpu();
|
|
|
|
}
|
|
|
|
|
|
|
|
get currentCpu() {
|
|
|
|
return this.#currentCpu;
|
|
|
|
}
|
|
|
|
|
|
|
|
get nextCpu() {
|
|
|
|
return this.#nextCpu;
|
|
|
|
}
|
|
|
|
|
|
|
|
getRandomCpu() {
|
2023-04-19 22:06:05 +02:00
|
|
|
let randomIndex = this.#getRandomInt(0, this.#cpuList.length);
|
2023-04-19 19:57:22 +02:00
|
|
|
this.#cpuList[randomIndex]["name"] = this.#cpuList[randomIndex]["name"].split('@')[0];
|
|
|
|
return this.#cpuList[randomIndex];
|
|
|
|
}
|
|
|
|
|
2023-04-19 22:06:05 +02:00
|
|
|
#getRandomInt(min, max) {
|
2023-04-19 19:57:22 +02:00
|
|
|
min = Math.ceil(min);
|
|
|
|
max = Math.floor(max);
|
|
|
|
return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive
|
|
|
|
}
|
|
|
|
}
|