mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
products[].product -> products[].id
This commit is contained in:
parent
bbb68d86d5
commit
94bbe2361b
11 changed files with 48 additions and 48 deletions
|
@ -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) => {
|
||||
|
|
|
@ -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.')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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')
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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')
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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')
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue