From 5efe8fddc7b4db3033e72dbdf577b77a856a0937 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 6 Jan 2019 12:44:07 +0000 Subject: Split out sentence composer --- scripts/toy.groovy | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/toy.groovy b/scripts/toy.groovy index e927151..049ee56 100644 --- a/scripts/toy.groovy +++ b/scripts/toy.groovy @@ -238,11 +238,15 @@ def gagText = { t, p -> def showButtonG = { s, p, t = null -> return t != null ? showButton(gagText(s, p), t) : showButton(gagText(s, p)); }; +def compose = { texts -> + if (!texts || texts.isEmpty()) return null; + return texts.collect { + t -> t[getRandom(t.size())] + }.join(" ").capitalize(); +}; def present = { imageSpec, texts -> if (texts) { - show(texts.collect { - t -> t[getRandom(t.size())] - }.join(" ").capitalize()); + show(compose(texts)); } if (imageSpec) { return showImage(imageSpec); -- cgit v1.2.3