diff --git a/src/packer/core.clj b/src/packer/core.clj index 38ec814..c941f19 100644 --- a/src/packer/core.clj +++ b/src/packer/core.clj @@ -1,4 +1,6 @@ -(ns packer.core (:gen-class)) +(ns packer.core + (:require [packer.util :as util]) + (:gen-class)) (def profile #{:t-shirt :tablet}) @@ -25,9 +27,10 @@ (produce-items items nights i18n)))) (defn produce-all [store profile nights i18n] + (let [nights (util/ask-int (:nights? i18n))] (->> store keys (map (fn [category] [category (filter #(.contains profile (:key %)) (get store category))])) (filter #(not (empty? (second %)))) (map #(produce-category (first %) (second %) nights i18n)) - (clojure.string/join "\n\n"))) \ No newline at end of file + (clojure.string/join "\n\n")))) \ No newline at end of file diff --git a/src/packer/i18n/pl.clj b/src/packer/i18n/pl.clj index c6f157a..27ed596 100644 --- a/src/packer/i18n/pl.clj +++ b/src/packer/i18n/pl.clj @@ -1,6 +1,7 @@ (ns packer.i18n.pl (:gen-class)) (def dict { + :nights? "Na ile nocy jedziesz?" :electronics "Elektronika" :cloths "Ubrania" :t-shirt "T-shirt" diff --git a/src/packer/i18n/pl.json b/src/packer/i18n/pl.json new file mode 100644 index 0000000..0f104ba --- /dev/null +++ b/src/packer/i18n/pl.json @@ -0,0 +1,7 @@ +{ + "electronics": "Elektronika", + "cloths": "Ubrania", + "t-shirt": "T-shirt", + "smartphone": "Telefon komórkowy", + "tablet": "Tablet" +} \ No newline at end of file diff --git a/src/packer/util.clj b/src/packer/util.clj new file mode 100644 index 0000000..ef6bfc6 --- /dev/null +++ b/src/packer/util.clj @@ -0,0 +1,23 @@ +(ns packer.util (:gen-class)) + +(defn ask + ([question prompt] (print (str question prompt)) + (flush) + (read-line)) + ([question] (ask question " \u2192 "))) + +(defn try-parse-long [string] + (try (Long/parseLong string) + (catch NumberFormatException e nil))) + +(defn ask-int [question] + (let [number (try-parse-long (ask question))] + (if (nil? number) + (recur question) + number))) + +(defn ask-bool [question] + (let [answer (clojure.string/lower-case (ask question " (y/n) \u2192 "))] + (if (.contains "yn" answer) + (= "y" answer) + (recur question)))) \ No newline at end of file