db-vendo-client/parse/remark.js

113 lines
2 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'
}
})
2017-11-12 01:23:34 +01:00
// todo: is passing in profile necessary?
const parseRemark = (profile, r) => {
2018-06-01 11:12:54 +02:00
// todo: U "stop cancelled"?
// todo: C
2018-06-07 15:41:00 +02:00
// todo: find sth more reliable than this
if (r.type === 'P' && r.txtN.toLowerCase().trim() === 'journey cancelled') {
return {
type: 'status',
code: 'journey-cancelled',
text: r.txtN
// todo: `r.sIdx`
}
}
if (r.type === 'L') {
2018-06-01 11:12:54 +02:00
return {
type: 'status',
code: 'alternative-trip',
text: r.txtN,
journeyId: r.jid
}
}
2018-06-07 15:41:00 +02:00
if (r.type === 'A') {
return hints[r.code && r.code.trim().toLowerCase()] || null
}
if (r.type === 'R') {
2018-06-01 11:12:54 +02:00
// todo: how can we identify the individual types?
return {
type: 'status',
code: r.code,
text: r.txtN || ''
}
}
return null
2017-11-11 22:35:41 +01:00
}
module.exports = parseRemark