1 package net.pterodactylus.rhynodge.webpages.weather.wettercom
3 import net.pterodactylus.rhynodge.states.AbstractState
4 import java.time.LocalDateTime
7 * Contains the state parsed from [wetter.com](https://www.wetter.com/).
9 * @author [David ‘Bombe’ Roden](mailto:bombe@pterodactylus.net)
11 class WetterComState(val dateTime: LocalDateTime) : AbstractState(true) {
13 val hours: List<HourState> = mutableListOf()
15 fun addHour(hourState: HourState) {
16 (hours as MutableList<HourState>).add(hourState)
19 enum class WindDirection {
33 data class HourState(val hourIndex: Int, val temperature: Double, val rainProbability: Double, val rainAmount: Double, val windDirection: WindDirection, val windSpeed: Double, val description: String, val image: String) {
35 class Builder(private val hourIndex: Int) {
37 fun temperature(temperature: Double) = _1(temperature)
39 inner class _1(private val temperature: Double) {
41 fun rainProbability(rainProbability: Double) = _2(rainProbability)
43 inner class _2(private val rainProbability: Double) {
45 fun rainAmount(rainAmount: Double) = _3(rainAmount)
47 inner class _3(private val rainAmount: Double) {
49 fun windFrom(windDirection: WindDirection) = _4(windDirection);
51 inner class _4(private val windDirection: WindDirection) {
53 fun at(windSpeed: Double) = _5(windSpeed)
55 inner class _5(private val windSpeed: Double) {
57 fun describedAs(description: String) = _6(description)
59 inner class _6(private val description: String) {
61 fun withImage(imageUrl: String) = _7(imageUrl)
63 inner class _7(private val imageUrl: String) {
65 fun build(): HourState {
66 return HourState(hourIndex, temperature, rainProbability, rainAmount, windDirection, windSpeed, description, imageUrl)
87 fun atHour(hourIndex: Int) = Builder(hourIndex)
95 fun String.toWindDirection(): WetterComState.WindDirection {
97 "N" -> WetterComState.WindDirection.NORTH
98 "NE" -> WetterComState.WindDirection.NORTHEAST
99 "E" -> WetterComState.WindDirection.EAST
100 "SE" -> WetterComState.WindDirection.SOUTHEAST
101 "S" -> WetterComState.WindDirection.SOUTH
102 "SW" -> WetterComState.WindDirection.SOUTHWEST
103 "W" -> WetterComState.WindDirection.WEST
104 "NW" -> WetterComState.WindDirection.NORTHWEST
105 else -> WetterComState.WindDirection.NONE