products[].product -> products[].id

This commit is contained in:
Jannis R 2018-03-16 17:06:32 +01:00
parent bbb68d86d5
commit 94bbe2361b
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
11 changed files with 48 additions and 48 deletions

View file

@ -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) => {

View file

@ -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.')
}
}
}

View file

@ -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',

View file

@ -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',

View file

@ -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',

View file

@ -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',

View file

@ -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) {

View file

@ -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
}
}

View file

@ -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')
}
}

View file

@ -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')
}
}

View file

@ -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')
}
}