From d81c3a4efcc01408848882ad5307f5d9aa4f46c4 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Mon, 3 Jan 2022 19:41:06 -0500 Subject: [PATCH] Normalize the measurements when outputting ingredient Partial fix for #4 --- kitchen/src/cli.rs | 4 ++-- recipes/src/unit.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/kitchen/src/cli.rs b/kitchen/src/cli.rs index 4853361..f9b010d 100644 --- a/kitchen/src/cli.rs +++ b/kitchen/src/cli.rs @@ -104,7 +104,7 @@ pub fn output_ingredients_list(rs: Vec) { acc.accumulate_from(&r); } for (_, i) in acc.ingredients() { - print!("{}", i.amt); + print!("{}", i.amt.normalize()); println!(" {}", i.name); } } @@ -118,7 +118,7 @@ pub fn output_ingredients_csv(rs: Vec) { let mut writer = csv::Writer::from_writer(out); for (_, i) in acc.ingredients() { writer - .write_record(&[format!("{}", i.amt), i.name]) + .write_record(&[format!("{}", i.amt.normalize()), i.name]) .expect("Failed to write csv."); } } diff --git a/recipes/src/unit.rs b/recipes/src/unit.rs index 5cecf0a..e60fb91 100644 --- a/recipes/src/unit.rs +++ b/recipes/src/unit.rs @@ -393,6 +393,14 @@ impl Measure { Weight(wm) => wm.plural(), } } + + pub fn normalize(self) -> Self { + match self { + Volume(vm) => Volume(vm.normalize()), + Count(qty) => Count(qty), + Weight(wm) => Weight(wm.normalize()), + } + } } impl Display for Measure {