From d909be3b653a9507f6c1e059bc40c4beeba7f591 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Thu, 7 Jun 2018 18:46:24 +0200 Subject: [PATCH] parseWarning --- lib/default-profile.js | 2 ++ lib/request.js | 4 ++++ lib/validate-profile.js | 1 + package.json | 1 + parse/warning.js | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 43 insertions(+) create mode 100644 parse/warning.js diff --git a/lib/default-profile.js b/lib/default-profile.js index d4d0ffcb..c7dbd27b 100644 --- a/lib/default-profile.js +++ b/lib/default-profile.js @@ -11,6 +11,7 @@ const parseMovement = require('../parse/movement') const parseNearby = require('../parse/nearby') const parseOperator = require('../parse/operator') const parseHint = require('../parse/hint') +const parseWarning = require('../parse/warning') const parseStopover = require('../parse/stopover') const formatAddress = require('../format/address') @@ -48,6 +49,7 @@ const defaultProfile = { parseNearby, parseOperator, parseHint, + parseWarning, parseStopover, formatAddress, diff --git a/lib/request.js b/lib/request.js index 4dddaad5..8817d3b9 100644 --- a/lib/request.js +++ b/lib/request.js @@ -83,6 +83,10 @@ const request = (profile, data) => { if (Array.isArray(c.remL)) { d.hints = c.remL.map(hint => profile.parseHint(profile, hint)) } + d.warnings = [] + if (Array.isArray(c.himL)) { + d.warnings = c.himL.map(w => profile.parseWarning(profile, w)) + } if (Array.isArray(c.opL)) { d.operators = c.opL.map(op => profile.parseOperator(profile, op)) } diff --git a/lib/validate-profile.js b/lib/validate-profile.js index 267ab0e7..38ed6cd8 100644 --- a/lib/validate-profile.js +++ b/lib/validate-profile.js @@ -21,6 +21,7 @@ const types = { parseNearby: 'function', parseOperator: 'function', parseHint: 'function', + parseWarning: 'function', parseStopover: 'function', formatAddress: 'function', diff --git a/package.json b/package.json index 7ab50742..17d200ab 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ }, "dependencies": { "@mapbox/polyline": "^1.0.0", + "br2nl": "^1.0.0", "capture-stack-trace": "^1.0.0", "create-hash": "^1.2.0", "fetch-ponyfill": "^6.0.0", diff --git a/parse/warning.js b/parse/warning.js new file mode 100644 index 00000000..f6e1ce2f --- /dev/null +++ b/parse/warning.js @@ -0,0 +1,35 @@ +'use strict' + +const brToNewline = require('br2nl') + +const parseDateTime = require('./date-time') + +// todo: is passing in profile necessary? +const parseWarning = (profile, w) => { + // todo: hid, act, pub, lead, tckr, icoX, fLocX, tLocX, prod, comp, + // todo: cat (1, 2), pubChL + // pubChL: + // [ { name: 'timetable', + // fDate: '20180606', + // fTime: '073000', + // tDate: '20180713', + // tTime: '030000' }, + // { name: 'export', + // fDate: '20180606', + // fTime: '073000', + // tDate: '20180713', + // tTime: '030000' } ] + + return { + type: 'warning', + summary: brToNewline(w.head), + text: brToNewline(w.text), + priority: w.prio, + category: w.cat, // todo: parse to sth meaningful + validFrom: parseDateTime(profile, w.sDate, w.sTime).toISO(), + validUntil: parseDateTime(profile, w.eDate, w.eTime).toISO(), + modified: parseDateTime(profile, w.lModDate, w.lModTime).toISO() + } +} + +module.exports = parseWarning