Normalize the measurements when outputting ingredient

Partial fix for #4
This commit is contained in:
Jeremy Wall 2022-01-03 19:41:06 -05:00
parent bec67ddff9
commit d81c3a4efc
2 changed files with 10 additions and 2 deletions

View File

@ -104,7 +104,7 @@ pub fn output_ingredients_list(rs: Vec<Recipe>) {
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<Recipe>) {
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.");
}
}

View File

@ -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 {