diff options
Diffstat (limited to 'src/chef/utils.clj')
-rw-r--r-- | src/chef/utils.clj | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/chef/utils.clj b/src/chef/utils.clj index c2c6bc1..7f476a2 100644 --- a/src/chef/utils.clj +++ b/src/chef/utils.clj @@ -40,3 +40,16 @@ category-parents (map #(:categories/name %)) (cstr/join " > "))) + +(defn parse-ingredients [s] + (->> s + (re-seq #"([A-z0-9 ]*)=([0-9]*) ?([A-z]*)") + (map #(hash-map :description (nth % 1) + :amount (Integer/parseInt (nth % 2)) + :unit (nth % 3))))) + +(defn valid-ingredients? [s] + (and (string? s) + (->> s + (re-matches #"(([A-z0-9 ]*)=([0-9]*) ?([A-z]*)\n?)*") + some?))) |