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 ;
2025-01-10 19:21:27 +01:00
const fahrtNr = p . verkehrsmittel ? . nummer || p . transport ? . number || p . train ? . no || ( ( p . risZuglaufId || '' ) + '_' ) . split ( '_' ) [ 1 ] || p . verkehrsmittelNummer || ( ( p . mitteltext || '' ) + ' ' ) . split ( ' ' ) [ 1 ] ;
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
2025-01-03 10:57:24 +00:00
fahrtNr : String ( fahrtNr ) ,
name : p . verkehrsmittel ? . langText || 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
2025-01-09 12:26:42 +00:00
const adminCode = p . administrationId || p . administration ? . id || p . administration ? . administrationID ;
if ( adminCode ) {
res . adminCode = 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-09 12:26:42 +00:00
res . operator = profile . parseOperator ( ctx , p . verkehrsmittel ? . zugattribute || p . zugattribute || p . attributNotizen || p . administration ) ;
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
} ;