extractAbsenceCause function
Implementation
AbsenceCauseEntry? extractAbsenceCause(Bs4Element row, bool missingCause) {
double absencePercent = extractAbsencePercent(row.children[2]);
AbsenceType? type = _extractAbsenceType(row.children[3].text);
AbsenceCauses? cause = AbsenceCauses.values
.where((element) => row.children[6].text
.toLowerCase()
.startsWith(element.name.toLowerCase()))
.firstOrNull;
String? extendedCause =
_extractExtendedCause(row.children.elementAtOrNull(6));
Bs4Element? editButton = row.children[missingCause ? 6 : 7].find('a');
String? id = queriesFromSoup(editButton?.getAttrValue("href"))['id'];
String note = extendedCause ?? "";
String registeredDateString = row.children[4].text;
int firstSpace = registeredDateString.indexOf(RegExp(r'\s'));
int secondSpace = registeredDateString.indexOf(RegExp(r'\s'), firstSpace + 1);
String dateString = registeredDateString.substring(0, secondSpace);
DateTime registered = registeredTimeFormat.parse(dateString);
Bs4Element? skemaBrik = row.children[1].find('a');
if (skemaBrik != null && id != null && type != null) {
var event = extractModul(skemaBrik);
if (event != null) {
return AbsenceCauseEntry(
type: type,
id: id,
absence: absencePercent,
cause: cause,
expandedCause: extendedCause ?? "",
note: note,
registered: registered,
module: event);
}
}
return null;
}