Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default_region: add region_a to label where available #41

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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