add service Geojson to_polygon
This commit is contained in:
parent
e6cc95fc5f
commit
2bb57b1091
2 changed files with 52 additions and 0 deletions
10
app/services/geojson_service.rb
Normal file
10
app/services/geojson_service.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
class GeojsonService
|
||||
def self.to_polygon coordinates
|
||||
{
|
||||
geo: {
|
||||
type: "Polygon",
|
||||
coordinates: [coordinates]
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
42
spec/services/geojson_service_spec.rb
Normal file
42
spec/services/geojson_service_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe GeojsonService do
|
||||
describe '.toGeoJsonPolygon' do
|
||||
|
||||
let(:to_polygon_return) {
|
||||
{
|
||||
geo: {
|
||||
type: "Polygon",
|
||||
coordinates: [coordinates]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
subject { described_class.to_polygon coordinates }
|
||||
|
||||
describe 'coordinates are empty' do
|
||||
let(:coordinates) { '' }
|
||||
|
||||
it { expect(subject).to eq(to_polygon_return) }
|
||||
end
|
||||
|
||||
describe 'coordinates are informed' do
|
||||
let(:coordinates) {
|
||||
[
|
||||
[5.93536376953125,
|
||||
48.91888968903368],
|
||||
[5.93536376953125,
|
||||
49.26780455063753],
|
||||
[7.094421386718749,
|
||||
49.26780455063753],
|
||||
[7.094421386718749,
|
||||
48.91888968903368],
|
||||
[5.93536376953125,
|
||||
48.91888968903368]
|
||||
]
|
||||
}
|
||||
|
||||
it { expect(subject).to eq(to_polygon_return) }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue