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

rename 'polygon' field to 'shape' to match pelias/schema #134

Merged
merged 1 commit into from
Sep 10, 2020
Merged
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
10 changes: 5 additions & 5 deletions Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Document.prototype.toESDocument = function() {
popularity: this.popularity,
population: this.population,
addendum: {},
polygon: this.shape
shape: this.shape
};

// add encoded addendum namespaces
Expand Down Expand Up @@ -136,8 +136,8 @@ Document.prototype.toESDocument = function() {
if( !Object.keys( doc.addendum || {} ).length ){
delete doc.addendum;
}
if( !Object.keys( doc.polygon || {} ).length ){
delete doc.polygon;
if( !Object.keys( doc.shape || {} ).length ){
delete doc.shape;
}

return {
Expand Down Expand Up @@ -576,7 +576,7 @@ Document.prototype.getCentroid = function(){
};

// shape
Document.prototype.setPolygon = function( value ){
Document.prototype.setShape = function( value ){

validate.type('object', value);
validate.truthy(value);
Expand All @@ -585,7 +585,7 @@ Document.prototype.setPolygon = function( value ){
return this;
};

Document.prototype.getPolygon = function(){
Document.prototype.getShape = function(){
return this.shape;
};

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var poi = new Document( 'geoname', 'venue', 1003 )
.setAddendum('wikipedia', { slug: 'HackneyCityFarm' })
.setAddendum('geonames', { foreignkey: 1 })
.setCentroid({ lon: 0.5, lat: 50.1 })
.setPolygon( geojsonObject /* any valid geojson object */ )
.setShape( geojsonObject /* any valid geojson object */ )
.setBoundingBox( bboxObject /* see tests for bbox syntax */ );

console.log( poi );
Expand Down
2 changes: 1 addition & 1 deletion test/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ for( var x=0; x<iterations; x++ ){
.setPopulation(10)
.setPopularity(3)
.setCentroid({ lon: 0.5, lat: 50.1 })
.setPolygon(fixtures.new_zealand)
.setShape(fixtures.new_zealand)
.setBoundingBox(fixtures.new_zealand_bbox)
.toESDocument();
}
Expand Down
22 changes: 11 additions & 11 deletions test/document/polygon.js → test/document/shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@ var Document = require('../../Document');

module.exports.tests = {};

module.exports.tests.getPolygon = function(test) {
test('getPolygon', function(t) {
module.exports.tests.getShape = function(test) {
test('getShape', function(t) {
var doc = new Document('mysource','mylayer','myid');
doc.shape = { 'foo': 'bar' };
t.deepEqual(doc.getPolygon(), doc.shape, 'getter works');
t.deepEqual(doc.getShape(), doc.shape, 'getter works');
t.end();
});
};

module.exports.tests.setPolygon = function(test) {
test('setPolygon', function(t) {
module.exports.tests.setShape = function(test) {
test('setShape', function(t) {
var doc = new Document('mysource','mylayer','myid');
t.equal(doc.shape, undefined, 'polygon undefined');
t.equal(doc.setPolygon({ 'foo': 'bar' }), doc, 'chainable');
t.equal(doc.setShape({ 'foo': 'bar' }), doc, 'chainable');
t.deepEqual(doc.shape, { 'foo': 'bar' }, 'polygon set');
t.end();
});
test('setPolygon - validate', function(t) {
test('setShape - validate', function(t) {
var doc = new Document('mysource','mylayer','myid');
t.throws( doc.setPolygon.bind(doc,undefined), null, 'invalid type' );
t.throws( doc.setPolygon.bind(doc,''), null, 'invalid type' );
t.throws( doc.setPolygon.bind(doc,1), null, 'invalid type' );
t.throws( doc.setPolygon.bind(doc,[]), null, 'invalid type' );
t.throws( doc.setShape.bind(doc,undefined), null, 'invalid type' );
t.throws( doc.setShape.bind(doc,''), null, 'invalid type' );
t.throws( doc.setShape.bind(doc,1), null, 'invalid type' );
t.throws( doc.setShape.bind(doc,[]), null, 'invalid type' );
t.end();
});
};
Expand Down
8 changes: 4 additions & 4 deletions test/document/toESDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports.tests.toESDocument = function(test) {
});
doc.setPopulation(123);
doc.setPopularity(456);
doc.setPolygon({ key: 'value' });
doc.setShape({ key: 'value' });
doc.addCategory('category 1');
doc.addCategory('category 2');
doc.setAddendum('wikipedia', { slug: 'HackneyCityFarm' });
Expand Down Expand Up @@ -72,7 +72,7 @@ module.exports.tests.toESDocument = function(test) {
bounding_box: '{"min_lat":12.121212,"max_lat":13.131313,"min_lon":21.212121,"max_lon":31.313131}',
population: 123,
popularity: 456,
polygon: {
shape: {
key: 'value'
},
category: [
Expand Down Expand Up @@ -135,7 +135,7 @@ module.exports.tests.toESDocument = function(test) {
t.false(esDoc.data.hasOwnProperty('center_point'), 'should not include center');
t.false(esDoc.data.hasOwnProperty('population'), ' should not include population');
t.false(esDoc.data.hasOwnProperty('popularity'), ' should not include popularity');
t.false(esDoc.data.hasOwnProperty('polygon'), ' should not include polygon');
t.false(esDoc.data.hasOwnProperty('shape'), ' should not include shape');
t.end();

});
Expand Down Expand Up @@ -192,7 +192,7 @@ module.exports.tests.toESDocument = function(test) {
t.false(esDoc.data.hasOwnProperty('center_point'), 'should not include center');
t.false(esDoc.data.hasOwnProperty('population'), ' should not include population');
t.false(esDoc.data.hasOwnProperty('popularity'), ' should not include popularity');
t.false(esDoc.data.hasOwnProperty('polygon'), ' should not include polygon');
t.false(esDoc.data.hasOwnProperty('shape'), ' should not include shape');
t.end();

});
Expand Down
2 changes: 1 addition & 1 deletion test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var tests = [
require('./document/addendum.js'),
require('./document/address.js'),
require('./document/parent.js'),
require('./document/polygon.js'),
require('./document/shape.js'),
require('./document/category.js'),
require('./document/boundingbox.js'),
require('./document/source.js'),
Expand Down
2 changes: 1 addition & 1 deletion test/serialize/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports.tests.complete = function(test) {
.setAddendum('wikipedia', { slug: 'HackneyCityFarm' })
.setAddendum('geonames', { foreignkey: 1 })
.setCentroid({ lon: 0.5, lat: 50.1 })
.setPolygon(fixtures.new_zealand)
.setShape(fixtures.new_zealand)
.setBoundingBox(fixtures.new_zealand_bbox);

var s = serializeDeserialize( doc );
Expand Down