Permalink
Browse files

Cleaned up a bit, added printing of inventory / menu

  • Loading branch information...
1 parent ada1483 commit b93153836ef635ec97bc42969db24ca854c1a772 @zk committed Sep 29, 2010
Showing with 66 additions and 27 deletions.
  1. +66 −27 src/barista/core.clj
View
@@ -4,7 +4,12 @@
(def *full-inv* {:coffee 10
:decaf-coffee 10
:sugar 10
- :cream 10})
+ :cream 10
+ :steamed-milk 10
+ :foamed-milk 10
+ :espresso 10
+ :cocoa 10
+ :whipped-cream 10})
(def *inv* (ref *full-inv*))
@@ -18,14 +23,43 @@
:cocoa 0.90M
:whipped-cream 1.00M})
+(defn recipe [& args]
+ {:name (first args)
+ :ingredients (partition 2 (drop 1 args))})
+
+
(def *recipes* [(recipe "Coffee"
:coffee 3
:sugar 1
:cream 1)
(recipe "Decaf Coffee"
:decaf-coffee 3
:sugar 1
- :cream 1)])
+ :cream 1)
+ (recipe "Caffe Latte"
+ :espresso 2
+ :steamed-milk 1)
+ (recipe "Caffe Americano"
+ :espresso 3)
+ (recipe "Caffe Mocha"
+ :espresso 1
+ :cocoa 1
+ :steamed-milk 1
+ :whipped-cream 1)
+ (recipe "Cappuccino"
+ :espresso 2
+ :steamed-milk 1
+ :foamed-milk 1)])
+(defn price-for [rcp]
+ (reduce
+ +
+ (map #(let [type (first %)
+ amt (second %)]
+ (* (type *prices*) amt))
+ (:ingredients rcp))))
+
+(defn recipe-names []
+ (map :name *recipes*))
(defn restock [] (dosync (ref-set *inv* *full-inv*)))
@@ -37,41 +71,46 @@
(defn has-ingredients? [rcp]
(every? true? (map has-ingredient-amount? (:ingredients rcp))))
-(defn make-drink [rcp]
- (println "Making " (:name rcp) "...")
- (let [res (dosync
- (when (has-ingredients? rcp)
- (do
- (doall (map remove-ingredient (:ingredients rcp)))
- @*inv*)))]
- res))
-
(defn remove-ingredient [ing]
(let [type (first ing)
inv-amt (type @*inv*)
dec-by (second ing)]
(alter *inv* assoc type (- inv-amt dec-by))))
-(defn order [name]
+(defn make-drink! [rcp]
+ (dosync
+ (when (has-ingredients? rcp)
+ (do
+ (doall (map remove-ingredient (:ingredients rcp)))
+ @*inv*))))
+
+(defn order-drink [name]
(if-let [rcp (->> *recipes*
(filter #(= name (:name %)))
first)]
- (if (make-drink rcp)
- (str "Your " (:name rcp) " is ready!")
- (str "Sorry, we were short some ingredients for " (:name rcp)))
+ (if (make-drink! rcp)
+ (str "Dispensing: " (:name rcp))
+ (str "Out of Stock: " (:name rcp)))
"not found..."))
-(defn price [rcp]
- (reduce
- +
- (map #(let [type (first %)
- amt (second %)]
- (* (type *prices*) amt))
- (:ingredients rcp))))
+(defn prn-inv []
+ (println "Inventory:")
+ (doseq [[ing amt] @*inv*]
+ (println (str (name ing) "," amt))))
+
+(defn prn-menu []
+ (println "Menu:")
+ (doseq [[rcp idx]
+ (map list
+ *recipes*
+ (map inc (range (count *recipes*))))]
+ (println
+ (str idx "," (:name rcp) "," (price-for rcp) "," (has-ingredients? rcp)
+ ))))
+
+(defn app-startup []
+ (prn-inv)
+ (prn-menu))
+
-(defn recipe [& args]
- {:name (first args)
- :ingredients (partition 2 (drop 1 args))})
-(defn recipe-names []
- (map :name *recipes*))

0 comments on commit b931538

Please sign in to comment.