Handle plurals in report
This commit is contained in:
parent
8158fdcab3
commit
77a72329a8
1 changed files with 17 additions and 4 deletions
|
|
@ -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"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue