From 29c18b202b291304ee8b08c2387b25542f76c414 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 20 Mar 2017 00:54:41 +0100 Subject: mock data --- mock/dish.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 mock/dish.js (limited to 'mock/dish.js') 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; +} -- cgit v1.2.3-70-g09d2