add ability to change malt specific heat; add brew2F, org-food -> org-cook
[org-brew.git] / org-brew.el
blob9b11b66641460da92b967516e6eea9ce64235171
1 ;;; org-brew.el --- org-mode extensions for brewing ber
2 ;;
3 ;; Copyright (C) 2009 Erik Hetzner
4 ;;
5 ;; Author: Erik Hetzner <ehetzner@gmail.com>
6 ;;
7 ;; This file is NOT part of GNU Emacs.
8 ;;
9 ;; This program is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ;; calc functions for brewing
23 (require 'org-cook)
24 (require 'brew-calc)
26 (defun org-brew-get-aaus ()
27 (interactive)
28 (let* ((item (org-mand-parse-ingredient))
29 (amount (car item))
30 (ingredient (car (cdr item)))
31 (amount-in-oz (math-remove-units
32 (math-convert-units
33 (math-read-expr amount)
34 (math-read-expr "1 oz")))))
35 (save-excursion
36 (org-link-search ingredient)
37 (let* ((aa (math-read-number
38 (cdr (assoc "AA" (org-entry-properties)))))
39 (aau (math-mul amount-in-oz aa)))
40 (message "AAUs: %s" (math-format-number aau))))))
42 (defun org-brew-convert-ingredient (food-ingr)
43 (let* ((item (cdr (assq :item food-ingr)))
44 (amount-calc (cdr (assq :amount-calc food-ingr)))
45 (unit (math-units-in-expr-p amount-calc t)))
46 (cond ((or (eq (car unit) 'lb)
47 (eq (car unit) 'kg))
48 ;; grain
49 (append food-ingr
50 '((:brew-ingr-type . :grain))))
51 ((or (eq (car unit) 'oz)
52 (eq (car unit) 'g))
53 ;; hop
54 (let* ((time-str
55 (or (org-entry-get (point) "boil_time")
56 (and (string-match "\\([0-9]+\\) \\(m\\.\\|min\\)" item)
57 (match-string 1 item))))
58 (time (if time-str (string-to-int time-str)))
59 (alpha-str
60 (or (org-entry-get (point) "alpha")
61 (and (string-match "\\([0-9\\.]+\\)%" item)
62 (match-string 1 item))))
63 (alpha (if alpha-str (string-to-number alpha-str))))
64 (append food-ingr
65 `((:brew-ingr-type . :hop)
66 ,@(if time
67 (list (cons :boil-time time)))
68 ,@(if alpha
69 (list (cons :alpha alpha))))))))))
71 (defun org-brew-parse-ingredient-at-point ()
72 (org-brew-convert-ingredient (org-cook-parse-ingredient-at-point)))
74 (defun org-brew-get-ingredient-list ()
75 (let ((food-ingr-list (org-cook-get-recipe-ingredient-list)))
76 (mapcar (lambda (ingr)
77 (org-brew-convert-ingredient ingr))
78 food-ingr-list)))
80 ;(defun org-brew-calc-recipe-ibu ()
81 ; (interactive)
82 ; (let ((ingr-list (org-brew-get-ingredient-list))
83 ; (ibu 0))
84 ; (mapc (lambda (ingr)
85 ; (if (eq :hop (cdr (assq :brew-ingr-type ingr)))
86 ; (let ((time (
87 ; (setq ibu (+ ibu
88 ; (calcFunc-brewTinsethIBU
90 (defun org-brew-visit-ingredient (ingr)
91 (let ((ingr-name (replace-regexp-in-string
92 "\\(([^)]+)\\|[^A-Za-z() ]\\|AA\\)" "" (cdr (assq :item ingr)))))
93 (message "%s" ingr-name)
94 (org-open-file "/home/egh/w/org-brew/beersmith-hops.org" t nil
95 (format "*%s" ingr-name))))
97 (defun org-brew-visit-ingredient-at-point ()
98 (interactive)
99 (org-brew-visit-ingredient
100 (org-brew-parse-ingredient-at-point)))