-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
line.js
57 lines (50 loc) · 1.37 KB
/
line.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import slugg from 'slugg';
const parseLine = ({profile}, p) => {
if (!p) {
return null;
} // todo: handle this upstream
const name = p.line || p.addName || p.name || null; // wtf
const res = {
type: 'line',
// This is terrible, but FPTF demands an ID. Let's pray for HAFAS.
id:
p.prodCtx && p.prodCtx.lineId && slugg(p.prodCtx.lineId.trim())
|| name && slugg(name.trim())
|| null,
// todo: what is p.prodCtx.matchId? use as `id`? expose it.
fahrtNr: p.prodCtx && p.prodCtx.num || null,
name,
public: true,
};
// todo: what is p.number?
// todo: what is p.prodCtx.catCode?
if (p.prodCtx && 'string' === typeof p.prodCtx.admin) {
res.adminCode = p.prodCtx.admin;
}
if (p.prodCtx && 'string' === typeof p.prodCtx.catOut) {
const productName = p.prodCtx.catOut.trim();
if (productName != '') {
res.productName = productName;
}
}
if ('cls' in p) {
// todo: use profile.products.find() for this
const byBitmask = [];
for (let product of profile.products) {
for (let bitmask of product.bitmasks) {
byBitmask[bitmask] = product;
}
}
// todo: what if `p.cls` is the sum of two bitmasks?
const product = byBitmask[parseInt(p.cls)];
res.mode = product && product.mode || null;
res.product = product && product.id || null;
}
if (p.operator) {
res.operator = p.operator;
} // todo: move up
return res;
};
export {
parseLine,
};