Browse code

Add more options to 'weight' function

Joseph Weston authored on 05/12/2021 19:15:17
Showing 1 changed files
... ...
@@ -109,11 +109,14 @@
109 109
     (when (x :speed)
110 110
         (spaced (-> x :speed :quantity) (-> x :speed :unit))))
111 111
 
112
-(defn- weight [x]
113
-    (when (x :weight)
114
-     (spaced
115
-      (-> x :weight pounds)
116
-      (some->> x :quantity (str "for ") parenthesize))))
112
+(defn- weight
113
+    [x & {:keys [no-quantity unit] :or {no-quantity false unit pounds}}]
114
+    (let [unit (if (string? unit) #(spaced % unit) unit)]
115
+      (when (x :weight)
116
+        (spaced
117
+          (-> x :weight unit)
118
+          (when (not no-quantity)
119
+            (some->> x :quantity (str "for ") parenthesize))))))
117 120
 
118 121
 (defn- short-spell-description [spell]
119 122
   (spaced
... ...
@@ -228,7 +231,7 @@
228 231
        cost
229 232
      :Weight
230 233
        {:align :right}
231
-       weight)])
234
+       #(weight % :unit "lb" :no-quantity true))])
232 235
 
233 236
 (defn error-message
234 237
     [{e :err}]