geo_combine 0.2.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,14 +4,15 @@ RSpec.describe GeoCombine::Geoblacklight do
4
4
  include XmlDocs
5
5
  include JsonDocs
6
6
  include GeoCombine::Exceptions
7
- let(:full_geobl) { GeoCombine::Geoblacklight.new(full_geoblacklight) }
8
- let(:basic_geobl) { GeoCombine::Geoblacklight.new(basic_geoblacklight) }
7
+ let(:full_geobl) { described_class.new(full_geoblacklight) }
8
+ let(:basic_geobl) { described_class.new(basic_geoblacklight) }
9
+ let(:pre_v1_geobl) { described_class.new(geoblacklight_pre_v1) }
9
10
  describe '#initialize' do
10
11
  it 'parses metadata argument JSON to Hash' do
11
12
  expect(basic_geobl.instance_variable_get(:@metadata)).to be_an Hash
12
13
  end
13
14
  describe 'merges fields argument into metadata' do
14
- let(:basic_geobl) { GeoCombine::Geoblacklight.new(basic_geoblacklight, 'dc_identifier_s' => 'new one', "extra_field" => true)}
15
+ let(:basic_geobl) { described_class.new(basic_geoblacklight, 'dc_identifier_s' => 'new one', "extra_field" => true)}
15
16
  it 'overwrites existing metadata fields' do
16
17
  expect(basic_geobl.metadata['dc_identifier_s']).to eq 'new one'
17
18
  end
@@ -32,12 +33,9 @@ RSpec.describe GeoCombine::Geoblacklight do
32
33
  expect(valid_json?(basic_geobl.to_json)).to be_truthy
33
34
  end
34
35
  end
35
- let(:enhanced_geobl) { GeoCombine::Geoblacklight.new(basic_geoblacklight, 'layer_geom_type_s' => 'esriGeometryPolygon') }
36
+ let(:enhanced_geobl) { described_class.new(basic_geoblacklight, 'layer_geom_type_s' => 'esriGeometryPolygon') }
36
37
  before { enhanced_geobl.enhance_metadata }
37
38
  describe '#enhance_metadata' do
38
- it 'calls enhancement methods to validate document' do
39
- expect(enhanced_geobl.valid?).to be true
40
- end
41
39
  it 'enhances the dc_subject_sm field' do
42
40
  expect(enhanced_geobl.metadata['dc_subject_sm']).to include 'Boundaries', 'Inland Waters'
43
41
  end
@@ -113,6 +111,11 @@ RSpec.describe GeoCombine::Geoblacklight do
113
111
  expect(enhanced_geobl).to receive(:dct_references_validate!)
114
112
  enhanced_geobl.valid?
115
113
  end
114
+ it 'validates spatial bounding box' do
115
+ expect(JSON::Validator).to receive(:validate!).and_return true
116
+ expect { basic_geobl.valid? }
117
+ .to raise_error GeoCombine::Exceptions::InvalidGeometry
118
+ end
116
119
  end
117
120
  describe '#dct_references_validate!' do
118
121
  context 'with valid document' do
@@ -151,4 +154,32 @@ RSpec.describe GeoCombine::Geoblacklight do
151
154
  end
152
155
  end
153
156
  end
157
+ describe 'spatial_validate!' do
158
+ context 'when valid' do
159
+ it { full_geobl.spatial_validate! }
160
+ end
161
+ context 'when invalid' do
162
+ it { expect { basic_geobl.spatial_validate! }.to raise_error GeoCombine::Exceptions::InvalidGeometry }
163
+ end
164
+ end
165
+ describe 'upgrade_to_v1' do
166
+ before do
167
+ expect(pre_v1_geobl).to receive(:upgrade_to_v1).and_call_original
168
+ pre_v1_geobl.enhance_metadata
169
+ end
170
+
171
+ it 'tags with version' do
172
+ expect(pre_v1_geobl.metadata).to include('geoblacklight_version' => '1.0')
173
+ end
174
+
175
+ it 'properly deprecates fields' do
176
+ described_class::DEPRECATED_KEYS_V1.each do |k|
177
+ expect(pre_v1_geobl.metadata.keys).not_to include(k.to_s)
178
+ end
179
+ end
180
+
181
+ it 'normalizes slugs' do
182
+ expect(pre_v1_geobl.metadata).to include('layer_slug_s' => 'sde-columbia-esri-arcatlas-snow-ln')
183
+ end
184
+ end
154
185
  end
@@ -0,0 +1,163 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe GeoCombine::OGP do
4
+ include JsonDocs
5
+
6
+ subject(:ogp) { GeoCombine::OGP.new(ogp_harvard_raster) }
7
+ let(:ogp_tufts) { GeoCombine::OGP.new(ogp_tufts_vector) }
8
+ let(:ogp_line) { GeoCombine::OGP.new(ogp_harvard_line) }
9
+ let(:metadata) { ogp.instance_variable_get(:@metadata) }
10
+
11
+ describe '#initialize' do
12
+ it 'parses JSON into metadata Hash' do
13
+ expect(metadata).to be_an Hash
14
+ end
15
+ end
16
+
17
+ describe '#to_geoblacklight' do
18
+ it 'calls geoblacklight_terms to create a GeoBlacklight object' do
19
+ expect(ogp).to receive(:geoblacklight_terms).and_return({})
20
+ expect(ogp.to_geoblacklight).to be_an GeoCombine::Geoblacklight
21
+ end
22
+ end
23
+
24
+ describe '#geoblacklight_terms' do
25
+ describe 'builds a hash which maps metadata' do
26
+ it 'with dc_identifier_s' do
27
+ expect(ogp.geoblacklight_terms).to include(dc_identifier_s: 'HARVARD.SDE2.G1059_W57_1654_PF_SH1')
28
+ end
29
+ it 'with dc_title_s' do
30
+ expect(ogp.geoblacklight_terms).to include(dc_title_s: 'World Map, 1654 (Raster Image)')
31
+ end
32
+ it 'with dc_description_s sanitized' do
33
+ expect(ogp.geoblacklight_terms).to include(dc_description_s: metadata['Abstract'])
34
+ end
35
+ it 'with dc_rights_s' do
36
+ expect(ogp.geoblacklight_terms).to include(dc_rights_s: 'Public')
37
+ expect(ogp_line.geoblacklight_terms).to include(dc_rights_s: 'Restricted')
38
+ end
39
+ it 'with dct_provenance_s' do
40
+ expect(ogp.geoblacklight_terms).to include(dct_provenance_s: 'Harvard')
41
+ end
42
+ it 'with dct_references_s' do
43
+ expect(ogp.geoblacklight_terms).to include(:dct_references_s)
44
+ end
45
+ it 'with layer_id_s that is blank' do
46
+ expect(ogp.geoblacklight_terms)
47
+ .to include(layer_id_s: "#{metadata['WorkspaceName']}:#{metadata['Name']}")
48
+ end
49
+ it 'with layer_geom_type_s' do
50
+ expect(ogp.geoblacklight_terms).to include(:layer_geom_type_s)
51
+ end
52
+ it 'with layer_slug_s' do
53
+ expect(ogp.geoblacklight_terms)
54
+ .to include(layer_slug_s: 'harvard-g1059-w57-1654-pf-sh1')
55
+ end
56
+ it 'with solr_geom' do
57
+ expect(ogp.geoblacklight_terms).to include(:solr_geom)
58
+ end
59
+ it 'with dc_subject_sm' do
60
+ expect(ogp.geoblacklight_terms).to include(
61
+ dc_subject_sm: [
62
+ 'Maps', 'Human settlements', 'Cities and towns', 'Villages',
63
+ 'Bodies of water', 'Landforms', 'Transportation',
64
+ 'imageryBaseMapsEarthCover'
65
+ ]
66
+ )
67
+ end
68
+ it 'with dct_spatial_sm' do
69
+ expect(ogp.geoblacklight_terms).to include(
70
+ dct_spatial_sm: [
71
+ 'Earth', 'Northern Hemisphere', 'Southern Hemisphere',
72
+ 'Eastern Hemisphere', 'Western Hemisphere', 'Africa', 'Asia',
73
+ 'Australia', 'Europe', 'North America', 'South America',
74
+ 'Arctic regions'
75
+ ]
76
+ )
77
+ end
78
+ end
79
+ end
80
+
81
+ describe '#ogp_geom' do
82
+ it 'when Paper Map use Raster' do
83
+ expect(ogp.ogp_geom).to eq 'Raster'
84
+ end
85
+ it 'anything else, return it' do
86
+ expect(ogp_tufts.ogp_geom).to eq 'Polygon'
87
+ end
88
+ end
89
+
90
+ describe '#ogp_formats' do
91
+ context 'when Paper Map or Raster' do
92
+ it 'returns GeoTIFF' do
93
+ %w[Raster Paper\ Map].each do |datatype|
94
+ expect(ogp).to receive(:metadata).and_return('DataType' => datatype)
95
+ expect(ogp.ogp_formats).to eq 'GeoTIFF'
96
+ end
97
+
98
+ end
99
+ end
100
+ context 'when Polygon, Line, or Point' do
101
+ it 'returns Shapefile' do
102
+ %w[Polygon Line Point].each do |datatype|
103
+ expect(ogp).to receive(:metadata).and_return('DataType' => datatype)
104
+ expect(ogp.ogp_formats).to eq 'Shapefile'
105
+ end
106
+ end
107
+ end
108
+ context 'unknown data types' do
109
+ it 'throws exception' do
110
+ expect(ogp).to receive(:metadata).twice.and_return('DataType' => 'Unknown')
111
+ expect { ogp.ogp_formats }.to raise_error(ArgumentError, 'Unknown')
112
+ end
113
+ end
114
+ end
115
+
116
+ describe '#envelope' do
117
+ it 'properly formatted envelope' do
118
+ expect(ogp.envelope).to eq 'ENVELOPE(-180.0, 180.0, 90.0, -90.0)'
119
+ end
120
+ it 'fails on out-of-bounds envelopes' do
121
+ expect(ogp).to receive(:west).and_return(-181)
122
+ expect { ogp.envelope }.to raise_error(ArgumentError)
123
+ end
124
+ end
125
+
126
+ describe '#references' do
127
+ context 'harvard raster' do
128
+ it 'has wms and download services' do
129
+ expect(JSON.parse(ogp.references)).to include(
130
+ 'http://www.opengis.net/def/serviceType/ogc/wms' => 'http://pelham.lib.harvard.edu:8080/geoserver/wms',
131
+ 'http://schema.org/DownloadAction' => 'http://pelham.lib.harvard.edu:8080/HGL/HGLOpenDelivery'
132
+ )
133
+ end
134
+ end
135
+ context 'tufts vector' do
136
+ it 'has wms wfs services' do
137
+ expect(JSON.parse(ogp_tufts.references)).to include(
138
+ 'http://www.opengis.net/def/serviceType/ogc/wms' => 'http://geoserver01.uit.tufts.edu/wms',
139
+ 'http://www.opengis.net/def/serviceType/ogc/wfs' => 'http://geoserver01.uit.tufts.edu/wfs'
140
+ )
141
+ end
142
+ end
143
+ context 'harvard line' do
144
+ it 'has restricted services' do
145
+ expect(JSON.parse(ogp_line.references)).to include(
146
+ 'http://www.opengis.net/def/serviceType/ogc/wfs' => 'http://hgl.harvard.edu:8080/geoserver/wfs',
147
+ 'http://www.opengis.net/def/serviceType/ogc/wms' => 'http://hgl.harvard.edu:8080/geoserver/wms'
148
+ )
149
+ expect(JSON.parse(ogp_line.references)).not_to include('http://schema.org/DownloadAction')
150
+ end
151
+ end
152
+ end
153
+
154
+ describe 'valid geoblacklight schema' do
155
+ context 'harvard' do
156
+ it { expect { ogp.to_geoblacklight.valid? }.to_not raise_error }
157
+ it { expect { ogp_line.to_geoblacklight.valid? }.to_not raise_error }
158
+ end
159
+ context 'tufts' do
160
+ it { expect { ogp_tufts.to_geoblacklight.valid? }.to_not raise_error }
161
+ end
162
+ end
163
+ end
@@ -24,6 +24,7 @@ require 'fixtures/xml_docs'
24
24
  require 'fixtures/json_docs'
25
25
  require 'helpers'
26
26
  require 'rspec-html-matchers'
27
+ require 'byebug'
27
28
 
28
29
  RSpec.configure do |config|
29
30
  config.include Helpers
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geo_combine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Reed
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-05 00:00:00.000000000 Z
11
+ date: 2020-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rsolr
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,20 @@ dependencies:
24
38
  - - ">="
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: net-http-persistent
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: nokogiri
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -84,30 +112,30 @@ dependencies:
84
112
  name: bundler
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
- - - "~>"
115
+ - - ">="
88
116
  - !ruby/object:Gem::Version
89
- version: '1.7'
117
+ version: '0'
90
118
  type: :development
91
119
  prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
93
121
  requirements:
94
- - - "~>"
122
+ - - ">="
95
123
  - !ruby/object:Gem::Version
96
- version: '1.7'
124
+ version: '0'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: rake
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
- - - "~>"
129
+ - - ">="
102
130
  - !ruby/object:Gem::Version
103
- version: '10.0'
131
+ version: '0'
104
132
  type: :development
105
133
  prerelease: false
106
134
  version_requirements: !ruby/object:Gem::Requirement
107
135
  requirements:
108
- - - "~>"
136
+ - - ">="
109
137
  - !ruby/object:Gem::Version
110
- version: '10.0'
138
+ version: '0'
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: rspec
113
141
  requirement: !ruby/object:Gem::Requirement
@@ -155,15 +183,20 @@ files:
155
183
  - bin/geocombine
156
184
  - geo_combine.gemspec
157
185
  - lib/geo_combine.rb
186
+ - lib/geo_combine/bounding_box.rb
187
+ - lib/geo_combine/ckan_metadata.rb
158
188
  - lib/geo_combine/cli.rb
159
189
  - lib/geo_combine/esri_open_data.rb
160
190
  - lib/geo_combine/exceptions.rb
161
191
  - lib/geo_combine/fgdc.rb
162
192
  - lib/geo_combine/formats.rb
163
193
  - lib/geo_combine/formatting.rb
194
+ - lib/geo_combine/geo_blacklight_harvester.rb
164
195
  - lib/geo_combine/geoblacklight.rb
165
196
  - lib/geo_combine/geometry_types.rb
166
197
  - lib/geo_combine/iso19139.rb
198
+ - lib/geo_combine/ogp.rb
199
+ - lib/geo_combine/railtie.rb
167
200
  - lib/geo_combine/subjects.rb
168
201
  - lib/geo_combine/version.rb
169
202
  - lib/tasks/geo_combine.rake
@@ -187,23 +220,32 @@ files:
187
220
  - spec/features/fgdc2html_spec.rb
188
221
  - spec/features/iso2html_spec.rb
189
222
  - spec/fixtures/docs/basic_geoblacklight.json
223
+ - spec/fixtures/docs/ckan.json
190
224
  - spec/fixtures/docs/esri_open_data.json
191
225
  - spec/fixtures/docs/full_geoblacklight.json
226
+ - spec/fixtures/docs/geoblacklight_pre_v1.json
227
+ - spec/fixtures/docs/ogp_harvard_line.json
228
+ - spec/fixtures/docs/ogp_harvard_raster.json
229
+ - spec/fixtures/docs/ogp_tufts_vector.json
192
230
  - spec/fixtures/json_docs.rb
193
231
  - spec/fixtures/xml_docs.rb
194
232
  - spec/helpers.rb
233
+ - spec/lib/geo_combine/bounding_box_spec.rb
234
+ - spec/lib/geo_combine/ckan_metadata_spec.rb
195
235
  - spec/lib/geo_combine/esri_open_data_spec.rb
196
236
  - spec/lib/geo_combine/fgdc_spec.rb
197
237
  - spec/lib/geo_combine/formatting_spec.rb
238
+ - spec/lib/geo_combine/geo_blacklight_harvester_spec.rb
198
239
  - spec/lib/geo_combine/geoblacklight_spec.rb
199
240
  - spec/lib/geo_combine/iso19139_spec.rb
241
+ - spec/lib/geo_combine/ogp_spec.rb
200
242
  - spec/lib/geo_combine_spec.rb
201
243
  - spec/spec_helper.rb
202
244
  homepage: ''
203
245
  licenses:
204
246
  - Apache
205
247
  metadata: {}
206
- post_install_message:
248
+ post_install_message:
207
249
  rdoc_options: []
208
250
  require_paths:
209
251
  - lib
@@ -218,24 +260,32 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
260
  - !ruby/object:Gem::Version
219
261
  version: '0'
220
262
  requirements: []
221
- rubyforge_project:
222
- rubygems_version: 2.4.5.1
223
- signing_key:
263
+ rubygems_version: 3.0.3
264
+ signing_key:
224
265
  specification_version: 4
225
266
  summary: A Ruby toolkit for managing geospatial metadata
226
267
  test_files:
227
268
  - spec/features/fgdc2html_spec.rb
228
269
  - spec/features/iso2html_spec.rb
229
270
  - spec/fixtures/docs/basic_geoblacklight.json
271
+ - spec/fixtures/docs/ckan.json
230
272
  - spec/fixtures/docs/esri_open_data.json
231
273
  - spec/fixtures/docs/full_geoblacklight.json
274
+ - spec/fixtures/docs/geoblacklight_pre_v1.json
275
+ - spec/fixtures/docs/ogp_harvard_line.json
276
+ - spec/fixtures/docs/ogp_harvard_raster.json
277
+ - spec/fixtures/docs/ogp_tufts_vector.json
232
278
  - spec/fixtures/json_docs.rb
233
279
  - spec/fixtures/xml_docs.rb
234
280
  - spec/helpers.rb
281
+ - spec/lib/geo_combine/bounding_box_spec.rb
282
+ - spec/lib/geo_combine/ckan_metadata_spec.rb
235
283
  - spec/lib/geo_combine/esri_open_data_spec.rb
236
284
  - spec/lib/geo_combine/fgdc_spec.rb
237
285
  - spec/lib/geo_combine/formatting_spec.rb
286
+ - spec/lib/geo_combine/geo_blacklight_harvester_spec.rb
238
287
  - spec/lib/geo_combine/geoblacklight_spec.rb
239
288
  - spec/lib/geo_combine/iso19139_spec.rb
289
+ - spec/lib/geo_combine/ogp_spec.rb
240
290
  - spec/lib/geo_combine_spec.rb
241
291
  - spec/spec_helper.rb