From 189f5ecee0ddca7efde05f5eaa2d2e51df09e58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Mon, 16 May 2022 21:29:42 +0200 Subject: [PATCH] Trim whitespaces from strings in GradeSummary --- .../io/github/wulkanowy/sdk/scrapper/Utils.kt | 4 ++-- .../wulkanowy/sdk/scrapper/grades/GradesMapper.kt | 8 ++++---- .../wulkanowy/sdk/scrapper/grades/Oceny.json | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Utils.kt b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Utils.kt index c76e7855..030f8693 100644 --- a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Utils.kt +++ b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/Utils.kt @@ -33,14 +33,14 @@ fun LocalDate.getLastMonday(): LocalDate = with(previousOrSame(MONDAY)) fun LocalDate.getSchoolYear(): Int = if (month.value > 8) year else year - 1 fun getGradeShortValue(value: String?): String { - return when (value) { + return when (value?.trim()) { "celujący" -> "6" "bardzo dobry" -> "5" "dobry" -> "4" "dostateczny" -> "3" "dopuszczający" -> "2" "niedostateczny" -> "1" - else -> value ?: "" + else -> value.orEmpty().trim() } } diff --git a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/grades/GradesMapper.kt b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/grades/GradesMapper.kt index bff4942f..4093b826 100644 --- a/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/grades/GradesMapper.kt +++ b/sdk-scrapper/src/main/kotlin/io/github/wulkanowy/sdk/scrapper/grades/GradesMapper.kt @@ -49,13 +49,13 @@ fun GradesResponse.mapGradesSummary() = gradesWithSubjects.map { subject -> GradeSummary( visibleSubject = subject.visibleSubject, order = subject.order, - name = subject.name, + name = subject.name.trim(), average = subject.average, predicted = getGradeShortValue(subject.proposed), final = getGradeShortValue(subject.annual), - pointsSum = subject.pointsSum.takeIf { it != "-" }.orEmpty(), - proposedPoints = subject.proposedPoints.orEmpty(), - finalPoints = subject.finalPoints.orEmpty() + pointsSum = subject.pointsSum.takeIf { it != "-" }.orEmpty().trim(), + proposedPoints = subject.proposedPoints.orEmpty().trim(), + finalPoints = subject.finalPoints.orEmpty().trim(), ) }.sortedBy { it.name }.toList() diff --git a/sdk-scrapper/src/test/resources/io/github/wulkanowy/sdk/scrapper/grades/Oceny.json b/sdk-scrapper/src/test/resources/io/github/wulkanowy/sdk/scrapper/grades/Oceny.json index 26d18193..90b2c543 100644 --- a/sdk-scrapper/src/test/resources/io/github/wulkanowy/sdk/scrapper/grades/Oceny.json +++ b/sdk-scrapper/src/test/resources/io/github/wulkanowy/sdk/scrapper/grades/Oceny.json @@ -26,8 +26,8 @@ "KolorOceny": 15748172 } ], - "ProponowanaOcenaRoczna": "", - "OcenaRoczna": "", + "ProponowanaOcenaRoczna": " ", + "OcenaRoczna": " ", "ProponowanaOcenaRocznaPunkty": null, "OcenaRocznaPunkty": null, "Srednia": 0, @@ -67,7 +67,7 @@ } ], "ProponowanaOcenaRoczna": "3", - "OcenaRoczna": "dobry", + "OcenaRoczna": " dobry ", "ProponowanaOcenaRocznaPunkty": null, "OcenaRocznaPunkty": null, "Srednia": 0, @@ -147,7 +147,7 @@ } ], "ProponowanaOcenaRoczna": "4/5", - "OcenaRoczna": "bardzo dobry", + "OcenaRoczna": " bardzo dobry", "ProponowanaOcenaRocznaPunkty": null, "OcenaRocznaPunkty": null, "Srednia": 0, @@ -177,7 +177,7 @@ "KolorOceny": 0 } ], - "ProponowanaOcenaRoczna": "4-", + "ProponowanaOcenaRoczna": "4- ", "OcenaRoczna": "5-", "ProponowanaOcenaRocznaPunkty": null, "OcenaRocznaPunkty": null, @@ -199,8 +199,8 @@ "KolorOceny": 0 } ], - "ProponowanaOcenaRoczna": "", - "OcenaRoczna": "", + "ProponowanaOcenaRoczna": " ", + "OcenaRoczna": " ", "ProponowanaOcenaRocznaPunkty": null, "OcenaRocznaPunkty": null, "Srednia": 0,