Merge branch 'report-plurals' into 'main'

Handle plurals in report

See merge request kernald/reddit-magnet!13
This commit is contained in:
Marc Plano-Lesay 2025-05-02 00:28:30 +00:00
commit 555f8d3b0c

View file

@ -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<String, ProcessedMagnets>,
@ -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"));