db-vendo-client/parse/hint.js

172 lines
2.8 KiB
JavaScript
Raw Normal View History

2017-11-11 22:35:41 +01:00
'use strict'
2018-06-01 11:12:54 +02:00
const hints = Object.assign(Object.create(null), {
fb: {
type: 'hint',
2018-06-07 15:41:00 +02:00
code: 'bicycle-conveyance',
2018-06-01 11:12:54 +02:00
text: 'bicycles conveyed'
},
2018-06-07 15:41:00 +02:00
nf: {
type: 'hint',
code: 'no-bicycle-conveyance',
text: 'bicycles not conveyed'
},
2018-06-01 11:12:54 +02:00
k2: {
type: 'hint',
code: '2nd-class-only',
text: '2. class only'
},
eh: {
type: 'hint',
code: 'boarding-ramp',
text: 'vehicle-mounted boarding ramp available'
},
wv: {
type: 'hint',
code: 'wifi',
text: 'WiFi available'
},
sn: {
type: 'hint',
code: 'snacks',
text: 'snacks available for purchase'
},
bf: {
type: 'hint',
code: 'barrier-free',
text: 'barrier-free'
},
2018-06-07 15:41:00 +02:00
rg: {
type: 'hint',
code: 'barrier-free-vehicle',
text: 'barrier-free vehicle'
},
2018-06-01 11:12:54 +02:00
bt: {
type: 'hint',
code: 'on-board-bistro',
text: 'Bordbistro available'
},
br: {
type: 'hint',
code: 'on-board-restaurant',
text: 'Bordrestaurant available'
},
ki: {
type: 'hint',
code: 'childrens-area',
text: `children's area available`
},
ls: {
type: 'hint',
code: 'power-sockets',
text: 'power sockets available'
},
ev: {
type: 'hint',
code: 'replacement-service',
text: 'replacement service'
},
kl: {
type: 'hint',
code: 'air-conditioned',
text: 'air-conditioned vehicle'
2018-06-11 21:37:13 +02:00
},
r0: {
type: 'hint',
code: 'upward-escalator',
text: 'upward escalator'
},
au: {
type: 'hint',
code: 'elevator',
text: 'elevator available'
},
ck: {
type: 'hint',
code: 'komfort-checkin',
text: 'Komfort-Checkin available'
},
it: {
type: 'hint',
code: 'ice-sprinter',
text: 'ICE Sprinter service'
2018-06-01 11:12:54 +02:00
}
})
2017-11-12 01:23:34 +01:00
// todo: is passing in profile necessary?
const parseHint = (profile, h) => {
2018-06-01 11:12:54 +02:00
// todo: C
2018-06-11 18:41:53 +02:00
const text = h.txtN && h.txtN.trim() || ''
2018-06-07 15:41:00 +02:00
2018-06-11 19:50:44 +02:00
if (h.type === 'M') {
return {
type: 'status',
code: h.code || null,
summary: h.txtS && h.txtS.trim() || '',
text
}
}
if (h.type === 'D') {
return {
type: 'status',
code: h.code || null,
text
}
}
2018-06-07 15:41:00 +02:00
// todo: find sth more reliable than this
2018-06-11 18:41:53 +02:00
if (h.type === 'P' && text.toLowerCase() === 'journey cancelled') {
2018-06-07 15:41:00 +02:00
return {
type: 'status',
code: 'journey-cancelled',
2018-06-11 18:41:53 +02:00
text
// todo: `h.sIdx`
2018-06-07 15:41:00 +02:00
}
}
2018-06-11 18:41:53 +02:00
if (h.type === 'U' && text.toLowerCase() === 'stop cancelled') {
return {
type: 'status',
code: 'stop-cancelled',
text
}
}
// todo:
// {
// "type": "U",
// "code": "",
// "icoX": 3,
// "txtN": "entrance and exit not possible"
// }
if (h.type === 'U') {
return {
type: 'status',
2018-06-11 21:37:13 +02:00
code: h.code || null,
2018-06-11 18:41:53 +02:00
text
}
}
if (h.type === 'L') {
2018-06-01 11:12:54 +02:00
return {
type: 'status',
code: 'alternative-trip',
2018-06-11 18:41:53 +02:00
text,
journeyId: h.jid
2018-06-01 11:12:54 +02:00
}
}
if (h.type === 'A') {
return hints[h.code && h.code.trim().toLowerCase()] || null
2018-06-07 15:41:00 +02:00
}
if (h.type === 'R') {
2018-06-01 11:12:54 +02:00
// todo: how can we identify the individual types?
return {
type: 'status',
code: h.code,
2018-06-11 18:41:53 +02:00
text
2018-06-01 11:12:54 +02:00
}
}
return null
2017-11-11 22:35:41 +01:00
}
module.exports = parseHint