summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2015-01-18 12:33:16 +0100
committercos <cos>2015-01-25 22:32:38 +0100
commitaf1f5c05b22ed3a823561656c534b409b0343636 (patch)
treeb6d1c45e76920e199b9bdf202c8fa649b4314e13
parent68cba16b9302bf0a0d2a50dbd959abc974da482e (diff)
downloadmat-af1f5c05b22ed3a823561656c534b409b0343636.zip
Combine repeated shopping list items when they have the same unit.
-rwxr-xr-xmat16
1 files changed, 12 insertions, 4 deletions
diff --git a/mat b/mat
index 807d269..4aa61be 100755
--- a/mat
+++ b/mat
@@ -716,9 +716,7 @@ sub cmd_shoppinglist {
for my $entry ( @$queue_entries ) {
my @s = $db->selectrow_array("SELECT servings FROM queue WHERE ".
"recipe_id=@$entry[0]");
-# $recipe_count{@$entry[0]} += $s[0]; FIXME Take number of servings into account
- print "WARNING ignoring servings for recipe @$entry[0]!\n" if($s[0] != 1);
- $recipe_count{@$entry[0]}++;
+ $recipe_count{@$entry[0]} += $s[0];
}
# map {print "| $_ = ${recipe_count{$_}}\n"} sort keys(%recipe_count);
@@ -766,7 +764,17 @@ sub cmd_shoppinglist {
}
}
my @sorted_ingredients = sort { $a->{ingredient} cmp $b->{ingredient} } @shop_ingredients;
- for my $shop ( @sorted_ingredients )
+ my @squeezed_ingredients;
+ for my $squeeze ( @sorted_ingredients )
+ {
+ if (exists($squeezed_ingredients[-1]) and $squeezed_ingredients[-1]{ingredient} eq $squeeze->{ingredient} and $squeezed_ingredients[-1]{unit} eq $squeeze->{unit}) {
+ $squeezed_ingredients[-1]{quantity} += $squeeze->{quantity};
+ } else {
+ push @squeezed_ingredients, $squeeze;
+ }
+ }
+# for my $shop ( @sorted_ingredients )
+ for my $shop ( @squeezed_ingredients )
{
printf "%4s %-8s %s\n", $shop->{quantity}, $shop->{unit}, $shop->{ingredient};
}