2017-11-11 22:35:41 +01:00
|
|
|
'use strict'
|
|
|
|
|
2017-12-16 01:23:11 +01:00
|
|
|
const slugg = require('slugg')
|
|
|
|
|
2017-12-12 03:28:54 +01:00
|
|
|
// todo: are p.number and p.line ever different?
|
|
|
|
// todo: operator from p.oprX?
|
2017-11-12 01:23:34 +01:00
|
|
|
const parseLine = (profile, p) => {
|
2017-11-11 23:56:09 +01:00
|
|
|
if (!p) return null // todo: handle this upstream
|
2017-11-20 15:08:30 +01:00
|
|
|
const res = {
|
|
|
|
type: 'line',
|
2017-12-16 01:23:11 +01:00
|
|
|
id: null,
|
2017-11-20 15:08:30 +01:00
|
|
|
name: p.line || p.name,
|
|
|
|
public: true
|
|
|
|
}
|
2017-11-11 22:35:41 +01:00
|
|
|
|
2017-12-16 01:23:11 +01:00
|
|
|
// We don't get a proper line id from the API, so we use the trip nr here.
|
|
|
|
// todo: find a better way
|
|
|
|
if (p.prodCtx && p.prodCtx.num) res.id = p.prodCtx.num
|
|
|
|
// This is terrible, but FPTF demands an ID. Let's pray for VBB to expose an ID.
|
|
|
|
else if (p.line) res.id = slugg(p.line.trim())
|
|
|
|
else if (p.name) res.id = slugg(p.name.trim())
|
|
|
|
|
2017-11-11 23:56:09 +01:00
|
|
|
if (p.cls) res.class = p.cls
|
2017-12-12 18:31:41 +01:00
|
|
|
if (p.prodCtx && p.prodCtx.catCode !== undefined) {
|
|
|
|
res.productCode = +p.prodCtx.catCode
|
|
|
|
}
|
2017-11-11 23:56:09 +01:00
|
|
|
|
2017-11-12 21:23:29 +01:00
|
|
|
// todo: parse mode, remove from profiles
|
|
|
|
|
2017-11-11 23:56:09 +01:00
|
|
|
return res
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = parseLine
|