summaryrefslogtreecommitdiff
path: root/mock/dish.js
diff options
context:
space:
mode:
Diffstat (limited to 'mock/dish.js')
-rw-r--r--mock/dish.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/mock/dish.js b/mock/dish.js
new file mode 100644
index 0000000..5fc998a
--- /dev/null
+++ b/mock/dish.js
@@ -0,0 +1,38 @@
+
+const fs = require('fs')
+const path = require('path')
+
+const products = fs.readFileSync('./mock/data/products.default.txt').toString().split('\n')
+const techniques = fs.readFileSync('./mock/data/techniques.txt').toString().split('\n')
+const preparations = fs.readFileSync('./mock/data/preparations.txt').toString().split('\n')
+
+function choice(a){ return a[ randint(a.length) ]}
+function randint(n){ return Math.floor(Math.random()*n) }
+
+module.exports = function dish(n){
+ var pcount = randint(2) + 1;
+ var ps = [];
+ while (pcount-- > 0) ps.push(product());
+ if (randint(100) < 90) {
+ var d = ps.join(" and ") + " " + choice(preparations);
+ }
+ else {
+ var d = ps.join(", ");
+ }
+ return d;
+}
+function product(){
+ var result;
+ if (randint(100) > 1) {
+ var technique = choice(techniques);
+ if (technique[0] == '-') {
+ result = choice(products) + technique + " " + choice(products);
+ } else {
+ result = technique + " " + choice(products)
+ }
+ }
+ else {
+ result = choice(products)
+ }
+ return result;
+}