2017-11-11 22:35:41 +01:00
|
|
|
'use strict'
|
|
|
|
|
2017-12-16 01:23:11 +01:00
|
|
|
const slugg = require('slugg')
|
|
|
|
|
2018-06-13 19:59:44 +02:00
|
|
|
const createParseLine = (profile, opt, {operators}) => {
|
2018-03-16 17:00:06 +01:00
|
|
|
const byBitmask = []
|
|
|
|
for (let product of profile.products) {
|
|
|
|
for (let bitmask of product.bitmasks) {
|
|
|
|
byBitmask[bitmask] = product
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-23 15:36:57 +02:00
|
|
|
// todo: p.himIdL
|
2018-01-05 18:46:19 +01:00
|
|
|
const parseLine = (p) => {
|
|
|
|
if (!p) return null // todo: handle this upstream
|
2019-06-21 18:43:10 +02:00
|
|
|
const name = p.line || p.addName || p.name || null // wtf
|
2018-01-05 18:46:19 +01:00
|
|
|
const res = {
|
|
|
|
type: 'line',
|
2018-09-03 15:13:23 +02:00
|
|
|
// 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
|
|
|
|
),
|
2019-06-21 18:43:10 +02:00
|
|
|
// todo: what is p.prodCtx.matchId? use as `id`? expose it.
|
2018-08-22 19:02:56 +02:00
|
|
|
fahrtNr: p.prodCtx && p.prodCtx.num || null,
|
2018-09-03 15:13:23 +02:00
|
|
|
name,
|
2018-01-05 18:46:19 +01:00
|
|
|
public: true
|
|
|
|
}
|
2018-03-16 17:00:06 +01:00
|
|
|
// todo: what is p.number?
|
2018-12-10 20:42:37 +01:00
|
|
|
// todo: what is p.prodCtx.catCode?
|
2017-11-11 22:35:41 +01:00
|
|
|
|
2018-12-10 20:42:37 +01:00
|
|
|
if ('cls' in p) {
|
|
|
|
// todo: what if `p.cls` is the sum of two bitmasks?
|
|
|
|
const product = byBitmask[parseInt(p.cls)]
|
2018-03-16 17:06:32 +01:00
|
|
|
res.mode = product && product.mode || null
|
|
|
|
res.product = product && product.id || null
|
2018-03-16 17:00:06 +01:00
|
|
|
}
|
2017-11-12 21:23:29 +01:00
|
|
|
|
2018-01-05 18:46:19 +01:00
|
|
|
if ('number' === typeof p.oprX) {
|
|
|
|
res.operator = operators[p.oprX] || null
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
return parseLine
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
|
|
|
|
2018-01-05 18:46:19 +01:00
|
|
|
module.exports = createParseLine
|