Skip to content

Commit

Permalink
chore(tag_mapper): refactor tag mapping order
Browse files Browse the repository at this point in the history
This makes it easier to add custom logic by working through the tags in
a specified order.
  • Loading branch information
orangejulius committed Sep 24, 2021
1 parent 0ec1829 commit 13f065a
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions stream/tag_mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,27 @@ module.exports = function(){
return next( null, doc );
}

// Unfortunately we need to iterate over every tag,
// so we only do the iteration once to save CPU.
// handle the most likely source of name.default first
const trimmed_name = trim(tags.name);
if (trimmed_name) {
doc.setName('default', trimmed_name);
}

// check the other tags that might go into name.default second
Object.entries(NAME_SCHEMA).forEach(([key, value]) => {
if (value === 'default' && key !== 'name') {
const trimmed_value = trim(tags[key]);
if (trimmed_value) {
if (!trimmed_name ) {
doc.setName('default', trim( tags[key]));
} else {
doc.setNameAlias('default', trim( tags[key]));
}
}
}
});

// iterate through all tags, catching any address/localized names
_.each(tags, (value, key) => {

// Map localized names which begin with 'name:'
Expand All @@ -44,20 +63,6 @@ module.exports = function(){
}
}

// Map name data from our name mapping schema
else if( _.has(NAME_SCHEMA, key) ){
var val2 = trim( value );
if( val2 ){
if( key === NAME_SCHEMA._primary ){
doc.setName( NAME_SCHEMA[key], val2 );
} else if ( 'default' === NAME_SCHEMA[key] ) {
doc.setNameAlias( NAME_SCHEMA[key], val2 );
} else {
doc.setName( NAME_SCHEMA[key], val2 );
}
}
}

// Map address data from our address mapping schema
else if( _.has(ADDRESS_SCHEMA, key) ){
var val3 = trim( value );
Expand Down

0 comments on commit 13f065a

Please sign in to comment.