60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
const ParseTools = require("./ParseTools");
|
|
|
|
const parser = (text) => {
|
|
if(!ParseTools.isFilled(text)) return null;
|
|
|
|
const data = {
|
|
original: text,
|
|
changes: false,
|
|
note: null,
|
|
planned: text,
|
|
actual: text,
|
|
};
|
|
|
|
const hasBold = text.includes("<b> ");
|
|
const hasDel = text.includes("<del>");
|
|
|
|
if(hasBold) {
|
|
data.actual = text.split("<b> ")[1].split("</b>")[0];
|
|
if(hasDel) data.actual = data.actual.substring(1);
|
|
}
|
|
|
|
if(hasDel) {
|
|
data.planned = text.split("<del>")[1].split("</del>")[0];
|
|
data.changes = true;
|
|
if(text.substring(text.search("</del>") + 6) !== "") { // If it has reasoning/note
|
|
|
|
if(!hasBold) {
|
|
data.actual = null;
|
|
data.note = text.substring(text.search("</del>") + 6);
|
|
} else data.note = text.substring(text.search("</b>") + 5);
|
|
|
|
data.note = data.note.trim();
|
|
|
|
if(data.note === "") data.note = null;
|
|
|
|
} else data.actual = null;
|
|
} else data.planned = data.actual;
|
|
|
|
return data;
|
|
}
|
|
|
|
class TimetableDay {
|
|
#data = [];
|
|
|
|
anyChanges = false;
|
|
|
|
constructor(data) {
|
|
data.forEach((part, i) => {
|
|
this.#data[i] = parser(part);
|
|
if(this.#data[i]?.changes) this.anyChanges = true;
|
|
});
|
|
|
|
this.teacher = this.#data[0];
|
|
this.subject = this.#data[1];
|
|
this.room = this.#data[2];
|
|
this.exam = this.#data[3];
|
|
}
|
|
}
|
|
|
|
module.exports = TimetableDay; |