From 94bbe2361b7a405e5f781053ebbe82eab02e92cc Mon Sep 17 00:00:00 2001 From: Jannis R Date: Fri, 16 Mar 2018 17:06:32 +0100 Subject: [PATCH] products[].product -> products[].id --- format/products-filter.js | 4 ++-- lib/validate-profile.js | 8 ++++---- p/db/products.js | 20 ++++++++++---------- p/insa/products.js | 14 +++++++------- p/oebb/products.js | 20 ++++++++++---------- p/vbb/products.js | 14 +++++++------- parse/line.js | 6 +++--- parse/products-bitmask.js | 4 ++-- test/db.js | 2 +- test/insa.js | 2 +- test/oebb.js | 2 +- 11 files changed, 48 insertions(+), 48 deletions(-) diff --git a/format/products-filter.js b/format/products-filter.js index 90b1d06b..1305f501 100644 --- a/format/products-filter.js +++ b/format/products-filter.js @@ -7,8 +7,8 @@ const createFormatProductsFilter = (profile) => { const byProduct = {} const defaultProducts = {} for (let product of profile.products) { - byProduct[product.product] = product - defaultProducts[product.product] = product.default + byProduct[product.id] = product + defaultProducts[product.id] = product.default } const formatProductsFilter = (filter) => { diff --git a/lib/validate-profile.js b/lib/validate-profile.js index 8c05ebdb..21c86829 100644 --- a/lib/validate-profile.js +++ b/lib/validate-profile.js @@ -53,18 +53,18 @@ const validateProfile = (profile) => { } if (profile.products.length === 0) throw new Error('profile.products is empty.') for (let product of profile.products) { - if ('string' !== typeof product.product) { - throw new Error('profile.products[].product must be a string.') + if ('string' !== typeof product.id) { + throw new Error('profile.products[].id must be a string.') } if ('boolean' !== typeof product.default) { throw new Error('profile.products[].default must be a boolean.') } if (!Array.isArray(product.bitmasks)) { - throw new Error(product.product + '.bitmasks must be an array.') + throw new Error(product.id + '.bitmasks must be an array.') } for (let bitmask of product.bitmasks) { if ('number' !== typeof bitmask) { - throw new Error(product.product + '.bitmasks[] must be a number.') + throw new Error(product.id + '.bitmasks[] must be a number.') } } } diff --git a/p/db/products.js b/p/db/products.js index d1e26771..fa683e2b 100644 --- a/p/db/products.js +++ b/p/db/products.js @@ -3,7 +3,7 @@ // todo: https://gist.github.com/anonymous/d3323a5d2d6e159ed42b12afd0380434#file-haf_products-properties-L1-L95 module.exports = [ { - product: 'nationalExp', + id: 'nationalExp', mode: 'train', bitmasks: [1], name: 'InterCityExpress', @@ -11,7 +11,7 @@ module.exports = [ default: true }, { - product: 'national', + id: 'national', mode: 'train', bitmasks: [2], name: 'InterCity & EuroCity', @@ -19,7 +19,7 @@ module.exports = [ default: true }, { - product: 'regionalExp', + id: 'regionalExp', mode: 'train', bitmasks: [4], name: 'RegionalExpress & InterRegio', @@ -27,7 +27,7 @@ module.exports = [ default: true }, { - product: 'regional', + id: 'regional', mode: 'train', bitmasks: [8], name: 'Regio', @@ -35,7 +35,7 @@ module.exports = [ default: true }, { - product: 'suburban', + id: 'suburban', mode: 'train', bitmasks: [16], name: 'S-Bahn', @@ -43,7 +43,7 @@ module.exports = [ default: true }, { - product: 'bus', + id: 'bus', mode: 'bus', bitmasks: [32], name: 'Bus', @@ -51,7 +51,7 @@ module.exports = [ default: true }, { - product: 'ferry', + id: 'ferry', mode: 'watercraft', bitmasks: [64], name: 'Ferry', @@ -59,7 +59,7 @@ module.exports = [ default: true }, { - product: 'subway', + id: 'subway', mode: 'train', bitmasks: [128], name: 'U-Bahn', @@ -67,7 +67,7 @@ module.exports = [ default: true }, { - product: 'tram', + id: 'tram', mode: 'tram', bitmasks: [256], name: 'Tram', @@ -75,7 +75,7 @@ module.exports = [ default: true }, { - product: 'taxi', + id: 'taxi', mode: 'taxi', bitmasks: [512], name: 'Group Taxi', diff --git a/p/insa/products.js b/p/insa/products.js index 66bd63ec..485c3f23 100644 --- a/p/insa/products.js +++ b/p/insa/products.js @@ -2,7 +2,7 @@ module.exports = [ { - product: 'nationalExp', + id: 'nationalExp', mode: 'train', bitmasks: [1], name: 'InterCityExpress', @@ -10,7 +10,7 @@ module.exports = [ default: true }, { - product: 'national', + id: 'national', mode: 'train', bitmasks: [2], name: 'InterCity & EuroCity', @@ -18,7 +18,7 @@ module.exports = [ default: true }, { - product: 'regional', + id: 'regional', mode: 'train', bitmasks: [8], name: 'RegionalExpress & RegionalBahn', @@ -26,7 +26,7 @@ module.exports = [ default: true }, { - product: 'suburban', + id: 'suburban', mode: 'train', bitmasks: [16], name: 'S-Bahn', @@ -34,7 +34,7 @@ module.exports = [ default: true }, { - product: 'tram', + id: 'tram', mode: 'train', bitmasks: [32], name: 'Tram', @@ -42,7 +42,7 @@ module.exports = [ default: true }, { - product: 'bus', + id: 'bus', mode: 'bus', bitmasks: [64, 128], name: 'Bus', @@ -50,7 +50,7 @@ module.exports = [ default: true }, { - product: 'tourismTrain', + id: 'tourismTrain', mode: 'train', bitmasks: [256], name: 'Tourism Train', diff --git a/p/oebb/products.js b/p/oebb/products.js index 1c0fd223..91bcf65e 100644 --- a/p/oebb/products.js +++ b/p/oebb/products.js @@ -2,7 +2,7 @@ module.exports = [ { - product: 'nationalExp', + id: 'nationalExp', mode: 'train', bitmasks: [1], name: 'InterCityExpress & RailJet', @@ -10,7 +10,7 @@ module.exports = [ default: true }, { - product: 'national', + id: 'national', mode: 'train', bitmasks: [2, 4], name: 'InterCity & EuroCity', @@ -18,7 +18,7 @@ module.exports = [ default: true }, { - product: 'interregional', + id: 'interregional', mode: 'train', bitmasks: [8, 4096], name: 'Durchgangszug & EuroNight', @@ -26,7 +26,7 @@ module.exports = [ default: true }, { - product: 'regional', + id: 'regional', mode: 'train', bitmasks: [16], name: 'Regional & RegionalExpress', @@ -34,7 +34,7 @@ module.exports = [ default: true }, { - product: 'suburban', + id: 'suburban', mode: 'train', bitmasks: [32], name: 'S-Bahn', @@ -42,7 +42,7 @@ module.exports = [ default: true }, { - product: 'bus', + id: 'bus', mode: 'bus', bitmasks: [64], name: 'Bus', @@ -50,7 +50,7 @@ module.exports = [ default: true }, { - product: 'ferry', + id: 'ferry', mode: 'watercraft', bitmasks: [128], name: 'Ferry', @@ -58,7 +58,7 @@ module.exports = [ default: true }, { - product: 'subway', + id: 'subway', mode: 'train', bitmasks: [256], name: 'U-Bahn', @@ -66,7 +66,7 @@ module.exports = [ default: true }, { - product: 'tram', + id: 'tram', mode: 'train', bitmasks: [512], name: 'Tram', @@ -74,7 +74,7 @@ module.exports = [ default: true }, { - product: 'onCall', + id: 'onCall', mode: null, // todo bitmasks: [2048], name: 'On-call transit', diff --git a/p/vbb/products.js b/p/vbb/products.js index 678972ac..6d091247 100644 --- a/p/vbb/products.js +++ b/p/vbb/products.js @@ -2,7 +2,7 @@ module.exports = [ { - product: 'suburban', + id: 'suburban', mode: 'train', bitmasks: [1], name: 'S-Bahn', @@ -10,7 +10,7 @@ module.exports = [ default: true }, { - product: 'subway', + id: 'subway', mode: 'train', bitmasks: [2], name: 'U-Bahn', @@ -18,7 +18,7 @@ module.exports = [ default: true }, { - product: 'tram', + id: 'tram', mode: 'train', bitmasks: [4], name: 'Tram', @@ -26,7 +26,7 @@ module.exports = [ default: true }, { - product: 'bus', + id: 'bus', mode: 'bus', bitmasks: [8], name: 'Bus', @@ -34,7 +34,7 @@ module.exports = [ default: true }, { - product: 'ferry', + id: 'ferry', mode: 'watercraft', bitmasks: [16], name: 'Fähre', @@ -42,7 +42,7 @@ module.exports = [ default: true }, { - product: 'express', + id: 'express', mode: 'train', bitmasks: [32], name: 'IC/ICE', @@ -50,7 +50,7 @@ module.exports = [ default: true }, { - product: 'regional', + id: 'regional', mode: 'train', bitmasks: [64], name: 'RB/RE', diff --git a/parse/line.js b/parse/line.js index 36da3f26..fddc66e6 100644 --- a/parse/line.js +++ b/parse/line.js @@ -33,9 +33,9 @@ const createParseLine = (profile, operators) => { if ('class' in res) { // todo: what if `res.class` is the sum of two bitmasks? - const data = byBitmask[parseInt(res.class)] - res.mode = data && data.mode || null - res.product = data && data.product || null + const product = byBitmask[parseInt(res.class)] + res.mode = product && product.mode || null + res.product = product && product.id || null } if ('number' === typeof p.oprX) { diff --git a/parse/products-bitmask.js b/parse/products-bitmask.js index 3ebdb7d7..6b836904 100644 --- a/parse/products-bitmask.js +++ b/parse/products-bitmask.js @@ -4,7 +4,7 @@ const createParseBitmask = (profile) => { const defaultProducts = {} let withBitmask = [] for (let product of profile.products) { - defaultProducts[product.product] = false + defaultProducts[product.id] = false for (let bitmask of product.bitmasks) { withBitmask.push([bitmask, product]) } @@ -16,7 +16,7 @@ const createParseBitmask = (profile) => { for (let [pBitmask, product] of withBitmask) { if ((pBitmask & bitmask) > 0) { - res[product.product] = true + res[product.id] = true bitmask -= pBitmask } } diff --git a/test/db.js b/test/db.js index 62f39074..1df50fd6 100644 --- a/test/db.js +++ b/test/db.js @@ -73,7 +73,7 @@ const assertIsJungfernheide = (t, s) => { // todo: DRY with other tests const assertValidProducts = (t, p) => { for (let product of allProducts) { - product = product.product // wat + product = product.id t.equal(typeof p[product], 'boolean', 'product ' + p + ' must be a boolean') } } diff --git a/test/insa.js b/test/insa.js index 28679120..a5acfd04 100644 --- a/test/insa.js +++ b/test/insa.js @@ -58,7 +58,7 @@ const assertIsMagdeburgHbf = (t, s) => { // todo: DRY with other tests const assertValidProducts = (t, p) => { for (let product of allProducts) { - product = product.product // wat + product = product.id t.equal(typeof p[product], 'boolean', 'product ' + p + ' must be a boolean') } } diff --git a/test/oebb.js b/test/oebb.js index 7427b6db..f40d0655 100644 --- a/test/oebb.js +++ b/test/oebb.js @@ -77,7 +77,7 @@ const assertIsSalzburgHbf = (t, s) => { // todo: DRY with other tests const assertValidProducts = (t, p) => { for (let product of allProducts) { - product = product.product // wat + product = product.id t.equal(typeof p[product], 'boolean', 'product ' + p + ' must be a boolean') } }