Add filter and state for wetter.com
[rhynodge.git] / src / main / kotlin / net / pterodactylus / rhynodge / filters / webpages / wettercom / WetterComState.kt
1 package net.pterodactylus.rhynodge.filters.webpages.wettercom
2
3 import net.pterodactylus.rhynodge.states.AbstractState
4 import java.time.LocalDateTime
5
6 /**
7  * Contains the state parsed from [wetter.com](https://www.wetter.com/).
8  *
9  * @author [David ‘Bombe’ Roden](mailto:bombe@pterodactylus.net)
10  */
11 class WetterComState(val dateTime: LocalDateTime) : AbstractState(true) {
12
13     val hours: List<HourState> = mutableListOf()
14
15     fun addHour(hourState: HourState) {
16         (hours as MutableList<HourState>).add(hourState)
17     }
18
19     enum class WindDirection {
20
21         NONE,
22         NORTH,
23         NORTHEAST,
24         EAST,
25         SOUTHEAST,
26         SOUTH,
27         SOUTHWEST,
28         WEST,
29         NORTHWEST
30
31     }
32
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) {
34
35         class Builder(private val hourIndex: Int) {
36
37             fun temperature(temperature: Double) = _1(temperature)
38
39             inner class _1(private val temperature: Double) {
40
41                 fun rainProbability(rainProbability: Double) = _2(rainProbability)
42
43                 inner class _2(private val rainProbability: Double) {
44
45                     fun rainAmount(rainAmount: Double) = _3(rainAmount)
46
47                     inner class _3(private val rainAmount: Double) {
48
49                         fun windFrom(windDirection: WindDirection) = _4(windDirection);
50
51                         inner class _4(private val windDirection: WindDirection) {
52
53                             fun at(windSpeed: Double) = _5(windSpeed)
54
55                             inner class _5(private val windSpeed: Double) {
56
57                                 fun describedAs(description: String) = _6(description)
58
59                                 inner class _6(private val description: String) {
60
61                                     fun withImage(imageUrl: String) = _7(imageUrl)
62
63                                     inner class _7(private val imageUrl: String) {
64
65                                         fun build(): HourState {
66                                             return HourState(hourIndex, temperature, rainProbability, rainAmount, windDirection, windSpeed, description, imageUrl)
67                                         }
68
69                                     }
70
71                                 }
72
73                             }
74
75                         }
76
77                     }
78
79                 }
80
81             }
82
83         }
84
85         companion object {
86
87             fun atHour(hourIndex: Int) = Builder(hourIndex)
88
89         }
90
91     }
92
93 }
94
95 fun String.toWindDirection(): WetterComState.WindDirection {
96     return when (this) {
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
106     }
107 }