bom_buddy/
descriptor.rs

1use serde::{Deserialize, Serialize};
2use strum_macros::AsRefStr;
3
4// https://reg.bom.gov.au/info/forecast_icons.shtml
5#[derive(Debug, Serialize, Deserialize, AsRefStr)]
6#[serde(rename_all = "snake_case")]
7#[strum(serialize_all = "title_case")]
8pub enum IconDescriptor {
9    Sunny,
10    Clear,
11    MostlySunny,
12    PartlyCloudy,
13    Cloudy,
14    Hazy,
15    LightRain,
16    Windy,
17    Fog,
18    Shower,
19    Rain,
20    Dusty,
21    Frost,
22    Snow,
23    Storm,
24    LightShower,
25    HeavyShower,
26    Cyclone,
27}
28
29impl IconDescriptor {
30    // TODO: Add option to use nerd font weather icons. They don't look as nice but have proper
31    // icons for all descriptors at night time unlike emojis
32    // https://erikflowers.github.io/weather-icons/
33    pub fn get_icon_emoji(&self, is_night: bool) -> &str {
34        match self {
35            Self::Sunny if is_night => "🌙",
36            Self::Sunny => "☀️",
37            Self::Clear => "🌙",
38            Self::MostlySunny => "🌤️",
39            Self::PartlyCloudy => "⛅",
40            Self::Cloudy => "☁️",
41            Self::Hazy => "🌅",
42            Self::Windy => "🌬️",
43            Self::Fog => "🌫️",
44            Self::Shower => "🌦️",
45            Self::LightShower => "🌦️",
46            Self::LightRain => "🌦️",
47            Self::HeavyShower => "🌧️",
48            Self::Rain => "🌧️",
49            Self::Dusty => "🐪",
50            Self::Frost => "❄️",
51            Self::Snow => "🌨️",
52            Self::Storm => "⛈️",
53            Self::Cyclone => "🌀",
54        }
55    }
56
57    pub fn get_description(&self, is_night: bool) -> &str {
58        match self {
59            Self::Sunny if is_night => "Clear",
60            Self::MostlySunny if is_night => "Mostly Clear",
61            _ => self.as_ref(),
62        }
63    }
64}