Add support for questions

This commit is contained in:
2024-04-11 21:13:52 +02:00
parent f4a88f507f
commit 5bd8f9e6a7
4 changed files with 36 additions and 2 deletions

View File

@@ -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")))
(clojure.string/join "\n\n"))))

View File

@@ -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"

7
src/packer/i18n/pl.json Normal file
View File

@@ -0,0 +1,7 @@
{
"electronics": "Elektronika",
"cloths": "Ubrania",
"t-shirt": "T-shirt",
"smartphone": "Telefon komórkowy",
"tablet": "Tablet"
}

23
src/packer/util.clj Normal file
View File

@@ -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))))