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, } impl CurrentWeatherExtractor { pub fn new( current_weather: CurrentWeather, params: CurrentWeatherPrintParams, coords: Coordinates, city: Option, ) -> 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 } }