summaryrefslogtreecommitdiff
path: root/mock/dish.js
blob: 5fc998a5173fa0faf0c0d71b0d936f0e8466e145 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
}