Skip to content

Commit e4bf631

Browse files
committed
feat: cm as precipitation unit
This will be useful for daily/hourly units classes. The param method translates cm to mm, useful when it's an endpoint parameter.
1 parent 3fd8157 commit e4bf631

4 files changed

Lines changed: 14 additions & 5 deletions

File tree

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
package com.openmeteo.api.common.params
22

33
/**
4-
* The unit that should be used for precipitation
4+
* The unit used for precipitations
5+
*
6+
* When used as an endpoint parameter cm "becomes" mm through `?.param()`
57
*/
68
enum class PrecipitationUnit {
9+
cm,
710
mm,
8-
inch,
11+
inch;
12+
13+
/**
14+
* Called only when the unit is used as parameter
15+
*/
16+
fun param() =
17+
takeUnless { it == cm } ?: mm
918
}

lib/src/main/kotlin/com/openmeteo/api/ecmwf/EcmwfEndpoint.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class EcmwfEndpoint(
2929
"hourly" to hourly?.joinToString(","),
3030
"temperature_unit" to temperatureUnit,
3131
"windspeed_unit" to windSpeedUnit,
32-
"precipitation_unit" to precipitationUnit,
32+
"precipitation_unit" to precipitationUnit?.param(),
3333
"timeformat" to TimeFormat.unixtime,
3434
"past_days" to pastDays?.takeIf { it in 0..2 },
3535
"start_date" to startDate,

lib/src/main/kotlin/com/openmeteo/api/forecast/ForecastEndpoint.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ForecastEndpoint(
3636
"current_weather" to currentWeather,
3737
"temperature_unit" to temperatureUnit,
3838
"windspeed_unit" to windSpeedUnit,
39-
"precipitation_unit" to precipitationUnit,
39+
"precipitation_unit" to precipitationUnit?.param(),
4040
"timeformat" to TimeFormat.unixtime,
4141
"timezone" to (timeZone ?: daily?.let { "auto" }),
4242
"past_days" to pastDays?.takeIf { it in 0..2 },

lib/src/main/kotlin/com/openmeteo/api/historical/HistoricalEndpoint.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class HistoricalEndpoint(
3535
"daily" to daily?.joinToString(","),
3636
"temperature_unit" to temperatureUnit,
3737
"windspeed_unit" to windSpeedUnit,
38-
"precipitation_unit" to precipitationUnit,
38+
"precipitation_unit" to precipitationUnit?.param(),
3939
"timeformat" to TimeFormat.unixtime,
4040
"timezone" to (timeZone ?: daily?.let { "auto" }),
4141
)

0 commit comments

Comments
 (0)