1 ;;; org-brew.el --- org-mode extensions for brewing ber
3 ;; Copyright (C) 2009 Erik Hetzner
5 ;; Author: Erik Hetzner <ehetzner@gmail.com>
7 ;; This file is NOT part of GNU Emacs.
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
26 (defun org-brew-get-aaus ()
28 (let* ((item (org-mand-parse-ingredient))
30 (ingredient (car (cdr item
)))
31 (amount-in-oz (math-remove-units
33 (math-read-expr amount
)
34 (math-read-expr "1 oz")))))
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
)
50 '((:brew-ingr-type .
:grain
))))
51 ((or (eq (car unit
) 'oz
)
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
)))
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
))))
65 `((:brew-ingr-type .
:hop
)
67 (list (cons :boil-time time
)))
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
))
80 ;(defun org-brew-calc-recipe-ibu ()
82 ; (let ((ingr-list (org-brew-get-ingredient-list))
84 ; (mapc (lambda (ingr)
85 ; (if (eq :hop (cdr (assq :brew-ingr-type ingr)))
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 ()
99 (org-brew-visit-ingredient
100 (org-brew-parse-ingredient-at-point)))