mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-21 19:29:49 -04:00
Normalize the measurements when outputting ingredient
Partial fix for #4
This commit is contained in:
parent
bec67ddff9
commit
d81c3a4efc
@ -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.");
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user