2024-02-06 22:58:49 +01:00
import slugg from 'slugg' ;
2017-12-16 01:23:11 +01:00
2024-12-07 16:16:31 +00:00
const parseLine = ( ctx , p ) => {
const profile = ctx . profile ;
2024-12-11 23:51:58 +00:00
const fahrtNr = p . verkehrsmittel ? . nummer || p . transport ? . number || p . train ? . no ;
2019-10-20 00:19:11 +02:00
const res = {
type : 'line' ,
2025-01-02 14:00:45 +00:00
id : slugg ( p . verkehrsmittel ? . langText || p . transport ? . journeyDescription || p . train && p . train . category + ' ' + p . train . lineName + ' ' + p . train . no || p . langtext || p . mitteltext ) , // TODO terrible
fahrtNr : fahrtNr ? String ( fahrtNr ) : undefined , // TODO extract from zuglaufId?
name : p . verkehrsmittel ? . name || p . zugName || p . transport ? . journeyDescription || p . train && p . train . category + ' ' + p . train . lineName || p . langtext || p . mitteltext ,
2024-02-06 22:58:49 +01:00
public : true ,
} ;
2018-03-16 17:00:06 +01:00
2024-12-07 16:16:31 +00:00
// TODO res.adminCode
2025-01-02 14:00:45 +00:00
res . productName = p . verkehrsmittel ? . kurzText || p . transport ? . category || p . train ? . category || p . kurztext ;
const foundProduct = profile . products . find ( pp => pp . vendo == p . verkehrsmittel ? . produktGattung || pp . ris == p . transport ? . type || pp . ris == p . train ? . type || pp . ris _alt == p . train ? . type || pp . dbnav _short == p . produktGattung ) ;
2024-12-07 16:16:31 +00:00
res . mode = foundProduct ? . mode ;
res . product = foundProduct ? . id ;
2020-03-03 18:06:46 +01:00
2025-01-02 14:00:45 +00:00
res . operator = profile . parseOperator ( ctx , p . verkehrsmittel ? . zugattribute || p . zugattribute ) ; // TODO regio-guide op
2024-02-06 22:58:49 +01:00
return res ;
} ;
2017-11-11 22:35:41 +01:00
2022-05-07 16:17:37 +02:00
export {
parseLine ,
2024-02-06 22:58:49 +01:00
} ;