Several usability enhancements:

- You can now return "all" data available
 - The use of `Order.NAME_2` has been found and the item has been change to
 - `ORIGINAL_NAME` to reflect this
 - All `Order`-types now have their designated DSL method
 - It is now possible to search for items starting with a term
 - `inversion()` Order method has been renamed to `inversions()`
This commit is contained in:
Oliver Rümpelein 2020-04-26 14:39:57 +02:00
parent dc9124cd2e
commit d2dc84a17b
6 changed files with 65 additions and 11 deletions

View file

@ -19,7 +19,7 @@ fun generateNameQueryUrl() = rcdbQuery {
}
sortBy {
manufacturer()
inversion()
inversions()
}
}

View file

@ -10,13 +10,7 @@ enum class Order(
) : RcdbParamOption<Int> {
IMAGES("Images", "Amount of Images", 0),
NAME("Name", "Name of the Coaster", 1),
@Deprecated(
"The purpose of this parameter is yet unclear. You might want to use NAME instead",
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith("Order.NAME")
)
NAME_2("Name", "Name of the Coaster. Difference to NAME not clear", 2),
ORIGINAL_NAME("Original Name", "Original name of the Coaster, in local charset", 2),
LOCATION("Location", 3),
PARK("Park", 4),
OPENED("Opened", "Opening Date", 8),

View file

@ -9,6 +9,11 @@ sealed class RcdbParamOptionBuilder<out U : Any, T : RcdbParamOption<U>> {
return this
}
protected open fun addAll(items: Array<T>): RcdbParamOptionBuilder<U, T> {
paramList.addAll(items)
return this
}
fun build() = paramList.toList()
}
@ -32,7 +37,35 @@ class OrderBuilder : RcdbParamOptionBuilder<Int, Order>() {
return this
}
override fun addAll(items: Array<Order>): OrderBuilder {
super.addAll(items)
return this
}
fun of(order: Order) = this.add(order)
fun manufacturer() = this.add(Order.MANUFACTURER)
fun inversion() = this.add(Order.INVERSIONS)
fun inversions() = this.add(Order.INVERSIONS)
fun name() = this.add(Order.NAME)
fun location() = this.add(Order.LOCATION)
fun park() = this.add(Order.PARK)
fun opened() = this.add(Order.OPENED)
fun closed() = this.add(Order.CLOSED)
fun entered() = this.add(Order.ENTERED)
fun type() = this.add(Order.TYPE)
fun design() = this.add(Order.DESIGN)
fun classification() = this.add(Order.CLASSIFICATION)
fun layout() = this.add(Order.LAYOUT)
fun model() = this.add(Order.MODEL)
fun modelLine() = this.add(Order.MODEL_LINE)
fun speed() = this.add(Order.SPEED)
fun height() = this.add(Order.HEIGHT)
fun drop() = this.add(Order.DROP)
fun length() = this.add(Order.LENGTH)
fun angle() = this.add(Order.ANGLE)
fun serialNo() = this.add(Order.SERIAL_NO)
fun scale() = this.add(Order.SCALE)
fun rideTime() = this.add(Order.RIDE_TIME)
fun state() = this.add(Order.STATE)
fun closing() = this.add(Order.CLOSING)
fun all() = this.addAll(Order.values())
}

View file

@ -0,0 +1,27 @@
@file:Suppress("unused")
package de.pheerai.rcdbquery.dataMappings
import de.pheerai.rcdbquery.dsl.RcdbQueryParamsBuilder
class StartsWith(override val paramValue: String): RcdbParamOption<String> {
override val prettyName = "Starts with"
override val fullName = "Name starting with term"
companion object {
const val staticParamName = "nl"
}
}
fun RcdbQueryParamsBuilder.startsWith(term: String) {
if (StartsWith.staticParamName !in this.keys()) {
this[StartsWith.staticParamName] = listOf(
StartsWith(term)
)
} else {
error(
"""Only one starts with term must ever be set
| Old term: ${this[StartsWith.staticParamName]!![0].paramValue}
| New term: $term""".trimMargin()
)
}
}

View file

@ -18,7 +18,7 @@ class RcdbQueryDslTest {
of(Vendor.MAURER)
}
sortBy {
inversion()
inversions()
manufacturer()
}
}