summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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};
}