Skip to content

Commit

Permalink
feat(default_region): add region_a to label where available
Browse files Browse the repository at this point in the history
  • Loading branch information
missinglink committed Feb 4, 2021
1 parent 4ab82a1 commit cb369ca
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
8 changes: 8 additions & 0 deletions labelSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ function getRegionalValue(record) {

}

// return region_a unless record is a region itself
function getRegionalAbbreviation(record) {
if ('region' !== record.layer && !_.isEmpty(record.region_a)) {
return _.first(record.region_a);
}
}

// this function generates the last field of the labels for US records
// 1. use dependency name if layer is dependency, eg - Puerto Rico
// 2. use country name if layer is country, eg - United States
Expand Down Expand Up @@ -150,6 +157,7 @@ module.exports = {
'default': {
'valueFunctions': {
'local': getFirstProperty(['locality', 'localadmin']),
'regional': getRegionalAbbreviation,
'country': getFirstProperty(['dependency', 'country'])
}
},
Expand Down
25 changes: 17 additions & 8 deletions test/labelGenerator_default.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ module.exports.tests.default_country = function(test, common) {
'county': ['county name'],
'macrocounty': ['macrocounty name'],
'region': ['region name'],
'region_a': ['region abbrv'],
'macroregion': ['macroregion name'],
'country_a': ['country code'],
'country': ['country name']
};
t.equal(generator(doc),'venue name, locality name, country name');
t.equal(generator(doc),'venue name, locality name, region abbrv, country name');
t.end();
});

Expand All @@ -43,11 +44,12 @@ module.exports.tests.default_country = function(test, common) {
'county': ['county name'],
'macrocounty': ['macrocounty name'],
'region': ['region name'],
'region_a': ['region abbrv'],
'macroregion': ['macroregion name'],
'country_a': ['country code'],
'country': ['country name']
};
t.equal(generator(doc),'venue name, localadmin name, country name');
t.equal(generator(doc),'venue name, localadmin name, region abbrv, country name');
t.end();
});

Expand All @@ -63,11 +65,12 @@ module.exports.tests.default_country = function(test, common) {
'county': ['county name'],
'macrocounty': ['macrocounty name'],
'region': ['region name'],
'region_a': ['region abbrv'],
'macroregion': ['macroregion name'],
'country_a': ['country code'],
'country': ['country name']
};
t.equal(generator(doc),'house number street name, locality name, country name');
t.equal(generator(doc),'house number street name, locality name, region abbrv, country name');
t.end();
});

Expand All @@ -81,11 +84,12 @@ module.exports.tests.default_country = function(test, common) {
'county': ['county name'],
'macrocounty': ['macrocounty name'],
'region': ['region name'],
'region_a': ['region abbrv'],
'macroregion': ['macroregion name'],
'country_a': ['country code'],
'country': ['country name']
};
t.equal(generator(doc),'neighbourhood name, locality name, country name');
t.equal(generator(doc),'neighbourhood name, locality name, region abbrv, country name');
t.end();
});

Expand All @@ -98,11 +102,12 @@ module.exports.tests.default_country = function(test, common) {
'county': ['county name'],
'macrocounty': ['macrocounty name'],
'region': ['region name'],
'region_a': ['region abbrv'],
'macroregion': ['macroregion name'],
'country_a': ['country code'],
'country': ['country name']
};
t.equal(generator(doc),'locality name, country name');
t.equal(generator(doc),'locality name, region abbrv, country name');
t.end();
});

Expand All @@ -114,11 +119,12 @@ module.exports.tests.default_country = function(test, common) {
'county': ['county name'],
'macrocounty': ['macrocounty name'],
'region': ['region name'],
'region_a': ['region abbrv'],
'macroregion': ['macroregion name'],
'country_a': ['country code'],
'country': ['country name']
};
t.equal(generator(doc),'localadmin name, country name');
t.equal(generator(doc),'localadmin name, region abbrv, country name');
t.end();
});

Expand All @@ -129,11 +135,12 @@ module.exports.tests.default_country = function(test, common) {
'county': ['county name'],
'macrocounty': ['macrocounty name'],
'region': ['region name'],
'region_a': ['region abbrv'],
'macroregion': ['macroregion name'],
'country_a': ['country code'],
'country': ['country name']
};
t.equal(generator(doc),'county name, country name');
t.equal(generator(doc),'county name, region abbrv, country name');
t.end();
});

Expand All @@ -143,11 +150,12 @@ module.exports.tests.default_country = function(test, common) {
'layer': 'macrocounty',
'macrocounty': ['macrocounty name'],
'region': ['region name'],
'region_a': ['region abbrv'],
'macroregion': ['macroregion name'],
'country_a': ['country code'],
'country': ['country name']
};
t.equal(generator(doc),'macrocounty name, country name');
t.equal(generator(doc),'macrocounty name, region abbrv, country name');
t.end();
});

Expand All @@ -156,6 +164,7 @@ module.exports.tests.default_country = function(test, common) {
'name': { 'default': 'region name' },
'layer': 'region',
'region': ['region name'],
'region_a': ['region abbrv'],
'macroregion': ['macroregion name'],
'country_a': ['country code'],
'country': ['country name']
Expand Down
2 changes: 1 addition & 1 deletion test/labelSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports.tests.supported_countries = function(test, common) {
t.equals(Object.keys(schemas.KOR.valueFunctions).length, 3);
t.equals(Object.keys(schemas.FRA.valueFunctions).length, 2);
t.equals(Object.keys(schemas.ITA.valueFunctions).length, 3);
t.equals(Object.keys(schemas.default.valueFunctions).length, 2);
t.equals(Object.keys(schemas.default.valueFunctions).length, 3);

t.equals(Object.keys(schemas.KOR.meta).length, 1);
t.equals(schemas.KOR.meta.separator, ' ');
Expand Down

0 comments on commit cb369ca

Please sign in to comment.