Merge branch 'report-plurals' into 'main'
Handle plurals in report See merge request kernald/reddit-magnet!13
This commit is contained in:
commit
555f8d3b0c
1 changed files with 17 additions and 4 deletions
|
|
@ -8,6 +8,15 @@ static ROCKET: Emoji = Emoji("🚀", ":rocket:");
|
||||||
static LINK: Emoji = Emoji("🔗", ":link:");
|
static LINK: Emoji = Emoji("🔗", ":link:");
|
||||||
static WARNING: Emoji = Emoji("⚠️", ":warning:");
|
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
|
/// Generate a report of processed magnets
|
||||||
pub fn generate_report(
|
pub fn generate_report(
|
||||||
action_results: &HashMap<String, ProcessedMagnets>,
|
action_results: &HashMap<String, ProcessedMagnets>,
|
||||||
|
|
@ -21,8 +30,8 @@ pub fn generate_report(
|
||||||
SPARKLES,
|
SPARKLES,
|
||||||
style("Report Summary").bold().underlined(),
|
style("Report Summary").bold().underlined(),
|
||||||
style(format!(
|
style(format!(
|
||||||
"{} new links added to the database",
|
"{} added to the database",
|
||||||
total_new_links
|
pluralize(total_new_links, "new link", "new links")
|
||||||
))
|
))
|
||||||
.bold()
|
.bold()
|
||||||
.green(),
|
.green(),
|
||||||
|
|
@ -40,7 +49,11 @@ pub fn generate_report(
|
||||||
"{} {} {}\n",
|
"{} {} {}\n",
|
||||||
ROCKET,
|
ROCKET,
|
||||||
style(format!("{}", action_name)).bold().underlined().cyan(),
|
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 {
|
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));
|
let report = strip_ansi_codes(&generate_report(&action_results, total_new_links));
|
||||||
|
|
||||||
assert!(report.contains("Report Summary"));
|
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("TestAction"));
|
||||||
assert!(report.contains("Success: 1"));
|
assert!(report.contains("Success: 1"));
|
||||||
assert!(report.contains("Failure: 1"));
|
assert!(report.contains("Failure: 1"));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue