oeffisearch/src/backend/hafas/parse/line.nim

41 lines
928 B
Nim
Raw Normal View History

2020-02-07 14:09:42 +01:00
import ../types
import ../util
import ./products
import json
import options
proc parseLine*(common: CommonData, i: int): Option[Line] =
let l = common.lines[i]
2020-02-07 14:09:42 +01:00
# unparsable
if l{"cls"}.getInt == 0:
return options.none(Line)
2020-02-07 14:09:42 +01:00
let line = l.to(HafasProd)
var res = Line()
2020-02-07 14:09:42 +01:00
res.name = line.name
res.product = parseProduct(line.cls)
res.tripNum = line.prodCtx.num
res.productName = line.prodCtx.catOut
res.fullProductName = line.prodCtx.catOutL
res.id = slug(line.prodCtx.lineId.get(line.name))
2020-02-07 14:09:42 +01:00
if line.opX.isSome:
res.operator = some(common.operators[line.opX.get])
2020-02-07 14:09:42 +01:00
# DB
2020-02-07 14:09:42 +01:00
if line.nameS.isSome and (res.product == bus or res.product == tram or res.product == ferry):
res.name = line.nameS.get
2020-02-07 14:09:42 +01:00
if line.addName.isSome:
# swap name and addName
res.additionalName = some(res.name)
res.name = line.addName.get
2020-02-07 14:09:42 +01:00
# End DB
2020-02-07 14:09:42 +01:00
res.mode = MODES[int(res.product)]
return some(res)