summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2015-08-04 18:33:45 +0200
committercos <cos>2015-08-04 18:33:45 +0200
commit8e9c0e38bab593f3354efe8eaf62948d6adbcd11 (patch)
tree7fadda8c29c44121f02b29cabb3552054b44b54d
parent52cb72ed01bb5c8cc3b8255f289de081268efdfe (diff)
downloadmat-8e9c0e38bab593f3354efe8eaf62948d6adbcd11.zip
Energy density on labels, ask servings & show recipe second argument.
-rwxr-xr-xmat30
1 files changed, 21 insertions, 9 deletions
diff --git a/mat b/mat
index e920470..70e7bf5 100755
--- a/mat
+++ b/mat
@@ -369,7 +369,7 @@ sub print_label {
}
my $row3;
if ($energy) {
- $row3 = $energy.' kJ';
+ $row3 = $energy.' kJ ('.int($energy * 100 / $amount).' kJ/hg)';
} else {
$row3 = '<energy content unknown>';
}
@@ -696,7 +696,7 @@ sub cmd_addrecipe {
# FIXME Make it possible to provide name and uri as command line arguments
# instead of solely interactive mode.
- my ( $recipe_name, $uri, $answer, $sql );
+ my ( $recipe_name, $uri, $servings, $answer, $sql );
print "Recipe name: ";
$recipe_name = <STDIN>;
chomp $recipe_name;
@@ -704,9 +704,13 @@ sub cmd_addrecipe {
print "Recipe uri: ";
$uri = <STDIN>;
chomp $uri;
+ print "Servings: ";
+ $servings = <STDIN>;
+ chomp $servings;
- $sql = "INSERT INTO recipes (name, uri) VALUES (".$db->quote($recipe_name).
- ", ".$db->quote($uri).");";
+ $sql = "INSERT INTO recipes (name, uri, servings) VALUES (".
+ $db->quote($recipe_name).", ".$db->quote($uri).", ".
+ $db->quote($servings).");";
print "$sql\n\n";
print "Add to database? (y/n): ";
$answer = <STDIN>;
@@ -723,10 +727,11 @@ sub cmd_addrecipe {
sub cmd_showrecipe {
# Argument is recipe_id
- my ( $recipe_id ) = @_;
+ my ( $recipe_id, $desired_servings ) = @_;
my $recipe_row = $db->selectrow_arrayref("SELECT name, uri, servings FROM recipes WHERE id=".$recipe_id.";");
my $servings;
+ my $ingredient_multipler = 1;
print @$recipe_row[0];
if(defined(@$recipe_row[1])) {
@@ -736,7 +741,12 @@ sub cmd_showrecipe {
}
if(defined(@$recipe_row[2])) {
$servings = @$recipe_row[2];
- print "Serves: $servings\n\n"
+ if(defined($desired_servings)) {
+ print "Serves: $desired_servings\n\n";
+ $ingredient_multipler = $desired_servings/$servings;
+ } else {
+ print "Serves: $servings\n\n";
+ }
} else {
$servings = 1;
print "WARNING servings is not set for recipe $recipe_id!\n\n";
@@ -744,6 +754,7 @@ sub cmd_showrecipe {
my $contents = $db->selectall_hashref("SELECT * FROM contents WHERE recipe_id=".$recipe_id.";", 'ingredient_id');
for my $content ( keys(%$contents)) {
+ $$contents{$content}{quantity} = $$contents{$content}{quantity} * $ingredient_multipler;
my $ingredientcol = $db->selectrow_arrayref("SELECT name, primary_unit FROM ingredients WHERE id=".$content.";");
my $convert_unit;
my $convert_result;
@@ -925,8 +936,9 @@ sub cmd_shoppinglist {
print "\n";
}
open(my $f, "extrashopping.txt");
- my $extra = <$f>;
- print "$extra";
+ while(my $extra = <$f>) {
+ print "$extra";
+ }
return 1;
}
@@ -944,7 +956,7 @@ if ($ARGV[0]) {
} elsif ( $ARGV[0] eq "editrecipe") {
print "Command failed!\n" unless (cmd_editrecipe($ARGV[1]) >= 0);
} elsif ( $ARGV[0] eq "showrecipe") {
- print "Command failed!\n" unless (cmd_showrecipe($ARGV[1]) >= 0);
+ print "Command failed!\n" unless (cmd_showrecipe($ARGV[1], $ARGV[2]) >= 0);
} elsif ( $ARGV[0] eq "movemeal") {
print "Command failed!\n" unless (cmd_movemeal($ARGV[1], $ARGV[2]) >= 0);
} elsif ( $ARGV[0] eq "setmeal") {