Files
open-meteo-cli/src/current_weather_extractor.rs
T
midefos 1affcb9d1a
ci/woodpecker/push/woodpecker Pipeline was successful
Correct stdout, updating lib and some clippy clean
2023-07-30 18:13:42 +02:00

60 lines
1.8 KiB
Rust

use crate::current_weather_output::CurrentWeatherOutput;
use crate::{
coords::Coordinates, current_weather_print_params::CurrentWeatherPrintParams,
open_meteo::current_weather::CurrentWeather,
};
pub struct CurrentWeatherExtractor {
pub params: CurrentWeatherPrintParams,
current_weather: CurrentWeather,
coords: Coordinates,
city: Option<String>,
}
impl CurrentWeatherExtractor {
pub fn new(
current_weather: CurrentWeather,
params: CurrentWeatherPrintParams,
coords: Coordinates,
city: Option<String>,
) -> CurrentWeatherExtractor {
CurrentWeatherExtractor {
current_weather,
params,
coords,
city,
}
}
pub fn extract_output(&self) -> CurrentWeatherOutput {
let mut output = CurrentWeatherOutput::new(
self.params.format,
self.params.temperature_unit,
self.params.speed_unit,
);
if self.params.all || self.params.include_coords {
output.data.latitude = Some(self.coords.latitude);
output.data.longitude = Some(self.coords.longitude);
}
if self.params.all || self.params.include_city {
output.data.city = self.city.clone();
}
if self.params.is_day || self.params.all {
output.data.is_day = Some(self.current_weather.is_day);
}
if self.params.temperature || self.params.all {
output.data.temperature = Some(self.current_weather.temperature);
}
if self.params.windspeed || self.params.all {
output.data.windspeed = Some(self.current_weather.windspeed);
}
if self.params.winddirection || self.params.all {
output.data.winddirection = Some(self.current_weather.winddirection);
}
output
}
}