update cucumber suport code to return separate annotations headers

This commit is contained in:
karenzshea
2017-02-02 13:30:01 +01:00
committed by Patrick Niklaus
parent 84261fd214
commit ab91a05680
7 changed files with 69 additions and 87 deletions
+11 -17
View File
@@ -167,23 +167,17 @@ module.exports = function () {
if (!('annotation' in instructions.legs[0]))
return '';
function zip(list_1, list_2, list_3, list_4)
{
let tuples = [];
for (let i = 0; i < list_1.length; ++i) {
tuples.push([list_1[i], list_2[i], list_3[i], list_4[i]]);
}
return tuples;
}
return instructions.legs.map(l => {
const values = zip( l.annotation.weight, l.annotation.duration, l.annotation.distance, l.annotation.datasources);
return values.map(p => { return p.join(':'); }).join(',');
}).join(',');
};
this.OSMIDList = (instructions) => {
// OSM node IDs also come from the annotation list
return instructions.legs.map(l => l.annotation.nodes.map(n => n.toString()).join(',')).join(',');
var merged = {};
instructions.legs.map(l => {
Object.keys(l.annotation).forEach(a => {
if (!merged[a]) merged[a] = [];
merged[a].push(l.annotation[a].join(':'));
});
});
Object.keys(merged).map(a => {
merged[a] = merged[a].join(',');
});
return merged;
};
this.lanesList = (instructions) => {
+13 -3
View File
@@ -133,9 +133,19 @@ module.exports = function () {
got.locations = (locations || '').trim();
}
if (headers.has('annotation')){
got.annotation = (annotation || '').trim();
}
// if header matches 'a:*', parse out the values for *
// and return in that header
headers.forEach((k) => {
let whitelist = ['duration', 'distance', 'datasources', 'nodes', 'weight'];
if (k.match(/^a:/)) {
let a_type = k.slice(2);
if (whitelist.indexOf(a_type) == -1)
return cb(new Error('Unrecognized annotation field', a_type));
if (!annotation[a_type])
return cb(new Error('Annotation not found in response', a_type));
got[k] = annotation[a_type];
}
});
var putValue = (key, value) => {
if (headers.has(key)) got[key] = instructions ? value : '';