From 5b853a97521e62c5a53a861611a4c363b3cc6cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Pluta?= Date: Thu, 11 Apr 2024 22:03:56 +0200 Subject: [PATCH] Create preset generators --- src/packer/core.clj | 3 +-- src/packer/database.clj | 16 ++++++++++------ src/packer/main.clj | 5 +++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/packer/core.clj b/src/packer/core.clj index c941f19..0a6f789 100644 --- a/src/packer/core.clj +++ b/src/packer/core.clj @@ -27,10 +27,9 @@ (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/database.clj b/src/packer/database.clj index b846e19..48fd286 100644 --- a/src/packer/database.clj +++ b/src/packer/database.clj @@ -1,6 +1,7 @@ (ns packer.database (:use packer.model) - (:require packer.i18n.pl) + (:require packer.i18n.pl) + (:require [packer.util :as util]) (:gen-class)) ; Choose language to Polish @@ -19,9 +20,12 @@ ] }) +(defn simple-preset [question items seq] + (if (util/ask-bool question) + (concat seq items) + seq)) + ; Define profile getter -(defn get-profile [] - (->> store - vals - flatten - (map #(:key %)))) \ No newline at end of file +(defn get-profile [nights] + (->> [:t-shirt] + (simple-preset "Bierzesz telefon?" [:smartphone]))) \ No newline at end of file diff --git a/src/packer/main.clj b/src/packer/main.clj index d5614d1..9dc622a 100644 --- a/src/packer/main.clj +++ b/src/packer/main.clj @@ -1,8 +1,9 @@ (ns packer.main (:use packer.model) - (:require packer.core packer.database) + (:require packer.core packer.database packer.util) (:gen-class)) (defn -main [& args] - (println (packer.core/produce-all packer.database/store (packer.database/get-profile) 15 packer.database/i18n))) \ No newline at end of file + (let [nights (packer.util/ask-int (:nights? packer.database/i18n))] + (println (packer.core/produce-all packer.database/store (packer.database/get-profile nights) nights packer.database/i18n)))) \ No newline at end of file