mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
Preset#matchTags -> Preset#matchScore
This commit is contained in:
@@ -11,7 +11,7 @@ iD.presets.Category = function(id, category, all) {
|
||||
return category.geometry.indexOf(geometry) >= 0;
|
||||
};
|
||||
|
||||
category.matchTags = function() { return false; };
|
||||
category.matchScore = function() { return -1; };
|
||||
|
||||
category.name = function() {
|
||||
return t('presets.categories.' + id + '.name', {'default': id});
|
||||
|
||||
@@ -26,7 +26,7 @@ iD.presets.Collection = function(collection) {
|
||||
match;
|
||||
|
||||
for (var i = 0; i < collection.length; i++) {
|
||||
var score = collection[i].matchTags(entity);
|
||||
var score = collection[i].matchScore(entity);
|
||||
if (score > best) {
|
||||
best = score;
|
||||
match = collection[i];
|
||||
|
||||
@@ -12,7 +12,7 @@ iD.presets.Preset = function(id, preset, fields) {
|
||||
return preset.geometry.indexOf(geometry) >= 0;
|
||||
};
|
||||
|
||||
preset.matchTags = function(entity) {
|
||||
preset.matchScore = function(entity) {
|
||||
var tags = preset.tags,
|
||||
score = 0;
|
||||
for (var t in tags) {
|
||||
|
||||
@@ -50,23 +50,23 @@ describe('iD.presets.Preset', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#matchTags', function() {
|
||||
describe('#matchScore', function() {
|
||||
it("returns -1 if preset does not match tags", function() {
|
||||
expect(p['highway/residential'].matchTags(w1)).to.equal(-1);
|
||||
expect(p['highway/residential'].matchScore(w1)).to.equal(-1);
|
||||
});
|
||||
|
||||
it("returns 0 for other preset (no match tags)", function() {
|
||||
expect(p.other.matchTags(w1)).to.equal(0);
|
||||
expect(p.other.matchScore(w1)).to.equal(0);
|
||||
});
|
||||
|
||||
it("returns the number of matched tags", function() {
|
||||
expect(p['highway/residential'].matchTags(w3)).to.equal(1);
|
||||
expect(p['leisure/pitch/tennis'].matchTags(w2)).to.equal(2);
|
||||
expect(p['highway/residential'].matchScore(w3)).to.equal(1);
|
||||
expect(p['leisure/pitch/tennis'].matchScore(w2)).to.equal(2);
|
||||
});
|
||||
|
||||
it("counts * as a match for any value", function() {
|
||||
expect(p.building.matchTags(w4)).to.equal(0.5);
|
||||
expect(p.building.matchTags(w5)).to.equal(-1);
|
||||
expect(p.building.matchScore(w4)).to.equal(0.5);
|
||||
expect(p.building.matchScore(w5)).to.equal(-1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user