From d3815f80d730436109568a0e129fee45005caea7 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Wed, 27 Jun 2018 17:17:04 +0200 Subject: [PATCH] arrivals/departures: parse & expose platforms :sparkles: --- docs/changelog.md | 1 + parse/arrival-or-departure.js | 7 +++++++ test/lib/validators.js | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index 19bf6d8a..2f72255e 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -10,6 +10,7 @@ This version is not fully backwords-compatible. Check out [the migration guide]( - ac9819b `arrivals()` method – [docs](arrivals.md) - 21c273c `journeys()`/`journeyLeg()`: leg stopovers: parse & expose delays - 021ae45 `journeys()`/`journeyLeg()`: leg stopovers: parse & expose platforms +- 84bce0c `arrivals()`/`departures()`: parse & expose platforms - 85e0bdf `journeys()`: `startWithWalking` option with default `true` ### breaking changes 💥 diff --git a/parse/arrival-or-departure.js b/parse/arrival-or-departure.js index fef3d84f..e4cc0adb 100644 --- a/parse/arrival-or-departure.js +++ b/parse/arrival-or-departure.js @@ -37,6 +37,13 @@ const createParseArrOrDep = (profile, opt, data, prefix) => { res.delay = Math.round((realtime - planned) / 1000) } else res.delay = null + // todo: DRY with parseStopover + // todo: DRY with parseJourneyLeg + const pR = d.stbStop[prefix + 'PlatfR'] + const pP = d.stbStop[prefix + 'PlatfS'] + res.platform = pR || pP || null + // todo: `formerScheduledPlatform` + // todo: DRY with parseStopover // todo: DRY with parseJourneyLeg if (d.stbStop[prefix + 'Cncl']) { diff --git a/test/lib/validators.js b/test/lib/validators.js index f879c8d5..237674b4 100644 --- a/test/lib/validators.js +++ b/test/lib/validators.js @@ -243,6 +243,12 @@ const createValidateArrivalOrDeparture = (cfg) => { a.strictEqual(typeof dep.delay, 'number', msg) } + if (dep.platform !== null) { + const msg = name + '.platform must ' + a.strictEqual(typeof dep.platform, 'string', msg + 'be a string') + a.ok(dep.platform, name + 'not be empty') + } + val.line(val, dep.line, name + '.line') a.strictEqual(typeof dep.direction, 'string', name + '.direction must be a string') a.ok(dep.direction, name + '.direction must not be empty')