Fixes tag serialization.
This commit is contained in:
parent
b117439c4b
commit
b0953a9d66
2 changed files with 10 additions and 3 deletions
|
@ -45,7 +45,9 @@ value class Tag private constructor(val value: String) {
|
|||
private val splitter = Regex("\\s+")
|
||||
fun of(value: String): Tag =
|
||||
value.trim().let { v ->
|
||||
require(v.matches(validator))
|
||||
require(v.matches(validator)) {
|
||||
"\"$value\" isn't a valid tag"
|
||||
}
|
||||
Tag(v.lowercase())
|
||||
}
|
||||
|
||||
|
|
|
@ -52,11 +52,16 @@ private val tagSplitRegex = Regex("\\s+")
|
|||
|
||||
object TagAdapter {
|
||||
fun parse(ser: String?): List<Tag> {
|
||||
return ser?.trim()?.let { if (it.isNotBlank()) it.split(tagSplitRegex).map { Tag.of(it) } else emptyList() }
|
||||
return ser?.trim()?.let {
|
||||
if (it.isNotBlank()) it
|
||||
.split(tagSplitRegex)
|
||||
.filter { it.isNotBlank() }
|
||||
.map { Tag.of(it) } else emptyList()
|
||||
}
|
||||
?: emptyList()
|
||||
}
|
||||
|
||||
fun List<Tag>.serialize() = if (this.isEmpty()) "" else this.joinToString(",") { it.value }
|
||||
fun List<Tag>.serialize() = if (this.isEmpty()) "" else this.joinToString(" ") { it.value }
|
||||
}
|
||||
|
||||
fun List<Document>.grouped(): Map<Int, Map<Month, List<Document>>> =
|
||||
|
|
Loading…
Reference in a new issue