-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch from querying solr using rectangle to envelope syntax
- Loading branch information
1 parent
cb2bd65
commit 42cf848
Showing
7 changed files
with
109 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module Geoblacklight | ||
## | ||
# Transforms and parses a bounding box for various formats | ||
class BoundingBox | ||
## | ||
# @param [String, Integer, Float] west | ||
# @param [String, Integer, Float] south | ||
# @param [String, Integer, Float] east | ||
# @param [String, Integer, Float] north | ||
def initialize(west, south, east, north) | ||
@west = west | ||
@south = south | ||
@east = east | ||
@north = north | ||
# TODO: check for valid Geometry and raise if not | ||
end | ||
|
||
## | ||
# Returns a bounding box in ENVELOPE syntax | ||
# @return [String] | ||
def to_envelope | ||
"ENVELOPE(#{west}, #{east}, #{north}, #{south})" | ||
end | ||
|
||
## | ||
# Create a Geoblacklight::BoundingBox from a Solr rectangle syntax | ||
# @param [String] bbox as "W S E N" | ||
# @return [Geoblacklight::BoundingBox] | ||
def self.from_rectangle(rectangle) | ||
rectangle_array = rectangle.split(' ') | ||
fail Geoblacklight::Exceptions::WrongBoundingBoxFormat, 'Bounding box should be a string in Solr rectangle syntax e.g."W S E N"' if rectangle_array.count != 4 | ||
new( | ||
rectangle_array[0], | ||
rectangle_array[1], | ||
rectangle_array[2], | ||
rectangle_array[3] | ||
) | ||
end | ||
|
||
private | ||
|
||
attr_reader :west, :south, :east, :north | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'spec_helper' | ||
|
||
describe Geoblacklight::BoundingBox do | ||
describe '#initialize' do | ||
it 'handles multiple input types as arguments' do | ||
expect(Geoblacklight::BoundingBox.new('1', '1', '1', '1')).to be_an Geoblacklight::BoundingBox | ||
expect(Geoblacklight::BoundingBox.new(1, 2, 3, 3)).to be_an Geoblacklight::BoundingBox | ||
expect(Geoblacklight::BoundingBox.new(1.1, 2.1, 3.1, 3.1)).to be_an Geoblacklight::BoundingBox | ||
end | ||
end | ||
describe '#to_envelope' do | ||
let(:example_box) { Geoblacklight::BoundingBox.new(-160, -80, 120, 70) } | ||
it 'creates an envelope syntax version of the bounding box' do | ||
expect(example_box.to_envelope).to eq 'ENVELOPE(-160, 120, 70, -80)' | ||
end | ||
end | ||
describe '#from_rectangle' do | ||
let(:example_box) { Geoblacklight::BoundingBox.from_rectangle('-160 -80 120 70') } | ||
it 'parses and creates a Geoblacklight::BoundingBox from a Solr lat-lon' do | ||
expect(example_box).to be_an Geoblacklight::BoundingBox | ||
expect(example_box.to_envelope).to eq 'ENVELOPE(-160, 120, 70, -80)' | ||
end | ||
it 'checks for valididity' do | ||
expect { Geoblacklight::BoundingBox.from_rectangle('-160 -80 120') }.to raise_error Geoblacklight::Exceptions::WrongBoundingBoxFormat | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters