Adding format to select between normal, clean and JSON. This needs some refactor

This commit is contained in:
2023-06-13 18:38:32 +02:00
parent 9978e1553b
commit 8a3e5783c2
10 changed files with 507 additions and 306 deletions
+60
View File
@@ -0,0 +1,60 @@
use crate::current_weather_output::CurrentWeatherOutput;
use crate::{
coords::Coordinates, current_weather::CurrentWeather,
current_weather_print_params::CurrentWeatherPrintParams,
};
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);
}
return output;
}
}