diff --git a/src/report.rs b/src/report.rs index 327fe50..3da1112 100644 --- a/src/report.rs +++ b/src/report.rs @@ -8,6 +8,15 @@ static ROCKET: Emoji = Emoji("🚀", ":rocket:"); static LINK: Emoji = Emoji("🔗", ":link:"); static WARNING: Emoji = Emoji("⚠️", ":warning:"); +/// Helper function to handle pluralization +fn pluralize(count: usize, singular: &str, plural: &str) -> String { + if count == 1 { + format!("{} {}", count, singular) + } else { + format!("{} {}", count, plural) + } +} + /// Generate a report of processed magnets pub fn generate_report( action_results: &HashMap, @@ -21,8 +30,8 @@ pub fn generate_report( SPARKLES, style("Report Summary").bold().underlined(), style(format!( - "{} new links added to the database", - total_new_links + "{} added to the database", + pluralize(total_new_links, "new link", "new links") )) .bold() .green(), @@ -40,7 +49,11 @@ pub fn generate_report( "{} {} {}\n", ROCKET, style(format!("{}", action_name)).bold().underlined().cyan(), - style(format!("({} new links)", total_count)).bold() + style(format!( + "({})", + pluralize(total_count, "new link", "new links") + )) + .bold() )); if failed_count == 0 && success_count == 0 { @@ -205,7 +218,7 @@ mod tests { let report = strip_ansi_codes(&generate_report(&action_results, total_new_links)); assert!(report.contains("Report Summary")); - assert!(report.contains("1 new links added to the database")); + assert!(report.contains("1 new link added to the database")); assert!(report.contains("TestAction")); assert!(report.contains("Success: 1")); assert!(report.contains("Failure: 1"));