Remove indents from timetable parser
This commit is contained in:
parent
2c87de06ea
commit
b04c0fb296
1 changed files with 71 additions and 87 deletions
|
@ -63,8 +63,7 @@ class TimetableParser {
|
|||
}
|
||||
}
|
||||
divs.size == 2 -> getLessonInfo(lesson, divs[0])
|
||||
divs.size == 3 -> { // TODO: refactor this
|
||||
when {
|
||||
divs.size == 3 -> when { // TODO: refactor this
|
||||
divs[0]?.selectFirst("span")?.hasClass(CLASS_CHANGES) == true &&
|
||||
divs[1]?.selectFirst("span")?.hasClass(CLASS_MOVED_OR_CANCELED) == true &&
|
||||
divs[2]?.selectFirst("span")?.hasClass(CLASS_MOVED_OR_CANCELED) == true -> {
|
||||
|
@ -93,10 +92,7 @@ class TimetableParser {
|
|||
)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
getLessonInfo(lesson, divs[1])
|
||||
}
|
||||
}
|
||||
else -> getLessonInfo(lesson, divs[1])
|
||||
}
|
||||
else -> null
|
||||
}?.let {
|
||||
|
@ -107,9 +103,8 @@ class TimetableParser {
|
|||
}
|
||||
}
|
||||
|
||||
private fun getLessonInfo(lesson: Timetable, div: Element): Timetable {
|
||||
div.select("span").run {
|
||||
return when {
|
||||
private fun getLessonInfo(lesson: Timetable, div: Element) = div.select("span").run {
|
||||
when {
|
||||
size == 3 -> getSimpleLesson(lesson, this)
|
||||
size == 4 && last().hasClass(CLASS_REALIZED) -> getSimpleLesson(lesson, this)
|
||||
size == 4 -> getGroupLesson(lesson, this)
|
||||
|
@ -119,7 +114,6 @@ class TimetableParser {
|
|||
else -> lesson
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSimpleLesson(lesson: Timetable, spans: Elements): Timetable {
|
||||
return getLesson(lesson, spans)
|
||||
|
@ -137,8 +131,7 @@ class TimetableParser {
|
|||
return getLessonWithReplacement(lesson, spans, 1)
|
||||
}
|
||||
|
||||
private fun getLesson(lesson: Timetable, spans: Elements, offset: Int = 0): Timetable {
|
||||
return lesson.copy(
|
||||
private fun getLesson(lesson: Timetable, spans: Elements, offset: Int = 0) = lesson.copy(
|
||||
subject = getLessonAndGroupInfoFromSpan(spans[0])[0],
|
||||
group = getLessonAndGroupInfoFromSpan(spans[0])[1],
|
||||
teacher = spans[1 + offset].text(),
|
||||
|
@ -147,10 +140,8 @@ class TimetableParser {
|
|||
canceled = spans.first().hasClass(CLASS_MOVED_OR_CANCELED),
|
||||
changes = spans.first().hasClass(CLASS_CHANGES)
|
||||
)
|
||||
}
|
||||
|
||||
private fun getLessonWithReplacement(lesson: Timetable, spans: Elements, o: Int = 0): Timetable {
|
||||
return lesson.copy(
|
||||
private fun getLessonWithReplacement(lesson: Timetable, spans: Elements, o: Int = 0) = lesson.copy(
|
||||
subject = getLessonAndGroupInfoFromSpan(spans[3 + o])[0],
|
||||
subjectOld = getLessonAndGroupInfoFromSpan(spans[0])[0],
|
||||
group = getLessonAndGroupInfoFromSpan(spans[3 + o])[1],
|
||||
|
@ -161,26 +152,19 @@ class TimetableParser {
|
|||
info = "${getFormattedLessonInfo(spans.last().text())}, poprzednio: ${getLessonAndGroupInfoFromSpan(spans[0])[0]}",
|
||||
changes = true
|
||||
)
|
||||
}
|
||||
|
||||
private fun getFormattedLessonInfo(info: String?): String {
|
||||
return info?.removeSurrounding("(", ")") ?: ""
|
||||
}
|
||||
private fun getFormattedLessonInfo(info: String?) = info?.removeSurrounding("(", ")").orEmpty()
|
||||
|
||||
private fun stripLessonInfo(info: String): String {
|
||||
return info
|
||||
private fun stripLessonInfo(info: String) = info
|
||||
.replace("okienko dla uczniów", "")
|
||||
.replace("zmiana organizacji zajęć", "")
|
||||
.replace(" ,", "")
|
||||
.removePrefix(", ")
|
||||
}
|
||||
|
||||
private fun getLessonAndGroupInfoFromSpan(span: Element): Array<String> {
|
||||
return span.text().run {
|
||||
private fun getLessonAndGroupInfoFromSpan(span: Element) = span.text().let {
|
||||
arrayOf(
|
||||
span.text().substringBefore(" ["),
|
||||
if (this.contains("[")) span.text().split(" [").last().removeSuffix("]") else ""
|
||||
if (it.contains("[")) span.text().split(" [").last().removeSuffix("]") else ""
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue