// We must always wrap a return type of a filter in a Result. // This sometimes triggers a clippy warning. #![allow(clippy::unnecessary_wraps)] // We must always take references, even when it's not technically the fastest thing to do. // This sometimes also causes a clippy warning. #![allow(clippy::trivially_copy_pass_by_ref)] use crate::{ Player, ShotDetails, GoalDetails, SupportedLanguage, }; pub fn seconds_as_time(secs: &i32) -> ::askama::Result { let minutes = secs / 60; let seconds = secs % 60; Ok(format!("{minutes}:{seconds}")) } pub fn player_name(player: &Player) -> ::askama::Result { Ok(format!("{} {}", initials(&player.first_names)?, &player.last_name)) } pub fn goal_player_name(goal: &GoalDetails) -> ::askama::Result { Ok(format!("{} {}", initials(&goal.player_first_names)?, &goal.player_last_name)) } pub fn goal_assist_name(goal: &GoalDetails, lang: &SupportedLanguage) -> ::askama::Result { let Some(ref f_names) = goal.second_assist_first_names else { return Ok(lang.lookup("not-applicable")); }; let Some(ref l_name) = goal.second_assist_last_name else { return Ok(lang.lookup("not-applicable")); }; Ok(format!("{f_names} {l_name}")) } pub fn shot_assist_name(goal: &ShotDetails, lang: &SupportedLanguage) -> ::askama::Result { let Some(ref f_names) = goal.second_assist_first_names else { return Ok(lang.lookup("not-applicable")); }; let Some(ref l_name) = goal.second_assist_last_name else { return Ok(lang.lookup("not-applicable")); }; Ok(format!("{f_names} {l_name}")) } pub fn goal_second_assist_name(goal: &GoalDetails, lang: &SupportedLanguage) -> ::askama::Result { let Some(ref f_names) = goal.second_assist_first_names else { return Ok(lang.lookup("not-applicable")); }; let Some(ref l_name) = goal.second_assist_last_name else { return Ok(lang.lookup("not-applicable")); }; Ok(format!("{f_names} {l_name}")) } pub fn shot_second_assist_name(goal: &ShotDetails, lang: &SupportedLanguage) -> ::askama::Result { let Some(ref f_names) = goal.second_assist_first_names else { return Ok(lang.lookup("not-applicable")); }; let Some(ref l_name) = goal.second_assist_last_name else { return Ok(lang.lookup("not-applicable")); }; Ok(format!("{f_names} {l_name}")) } pub fn shot_player_name(shot: &ShotDetails) -> ::askama::Result { Ok(format!("{} {}", initials(&shot.player_first_names)?, &shot.player_last_name)) } pub fn initials(first_names: &str) -> ::askama::Result { Ok(format!("{}.", first_names .split_whitespace() .map(|name| &name[0..1]) .collect::>() .join("."))) } pub fn nullable(ot: &Option) -> ::askama::Result { match ot { Some(t) => Ok(format!("{t}")), None => Ok("NULL".to_string()) } }