iiif-presentation 1.4.2 → 1.5.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +8 -1
- data/.standard.yml +1 -0
- data/Gemfile +5 -5
- data/README.md +1 -1
- data/Rakefile +4 -2
- data/VERSION +1 -1
- data/bin/standardrb +16 -0
- data/iiif-presentation.gemspec +23 -23
- data/lib/iiif/hash_behaviours.rb +29 -33
- data/lib/iiif/ordered_hash.rb +33 -33
- data/lib/iiif/presentation/abstract_resource.rb +17 -22
- data/lib/iiif/presentation/annotation.rb +9 -11
- data/lib/iiif/presentation/annotation_list.rb +8 -10
- data/lib/iiif/presentation/canvas.rb +11 -13
- data/lib/iiif/presentation/collection.rb +7 -9
- data/lib/iiif/presentation/image_resource.rb +33 -35
- data/lib/iiif/presentation/layer.rb +8 -10
- data/lib/iiif/presentation/manifest.rb +9 -12
- data/lib/iiif/presentation/range.rb +8 -10
- data/lib/iiif/presentation/resource.rb +5 -7
- data/lib/iiif/presentation/sequence.rb +8 -11
- data/lib/iiif/presentation/service.rb +1 -2
- data/lib/iiif/presentation.rb +7 -7
- data/lib/iiif/service.rb +121 -102
- data/lib/iiif/v3/abstract_resource.rb +127 -130
- data/lib/iiif/v3/presentation/annotation.rb +20 -21
- data/lib/iiif/v3/presentation/annotation_collection.rb +7 -9
- data/lib/iiif/v3/presentation/annotation_page.rb +14 -15
- data/lib/iiif/v3/presentation/canvas.rb +21 -22
- data/lib/iiif/v3/presentation/choice.rb +14 -15
- data/lib/iiif/v3/presentation/collection.rb +7 -8
- data/lib/iiif/v3/presentation/image_resource.rb +21 -22
- data/lib/iiif/v3/presentation/manifest.rb +18 -19
- data/lib/iiif/v3/presentation/nav_place.rb +125 -29
- data/lib/iiif/v3/presentation/range.rb +10 -10
- data/lib/iiif/v3/presentation/resource.rb +4 -5
- data/lib/iiif/v3/presentation/sequence.rb +10 -11
- data/lib/iiif/v3/presentation/service.rb +12 -13
- data/lib/iiif/v3/presentation.rb +8 -8
- data/spec/integration/iiif/presentation/image_resource_spec.rb +54 -58
- data/spec/integration/iiif/service_spec.rb +76 -77
- data/spec/integration/iiif/v3/abstract_resource_spec.rb +72 -73
- data/spec/integration/iiif/v3/presentation/image_resource_spec.rb +53 -56
- data/spec/spec_helper.rb +56 -64
- data/spec/unit/iiif/hash_behaviours_spec.rb +384 -387
- data/spec/unit/iiif/ordered_hash_spec.rb +86 -91
- data/spec/unit/iiif/presentation/abstract_resource_spec.rb +64 -70
- data/spec/unit/iiif/presentation/annotation_list_spec.rb +1 -3
- data/spec/unit/iiif/presentation/annotation_spec.rb +1 -3
- data/spec/unit/iiif/presentation/canvas_spec.rb +11 -14
- data/spec/unit/iiif/presentation/collection_spec.rb +26 -33
- data/spec/unit/iiif/presentation/image_resource_spec.rb +4 -6
- data/spec/unit/iiif/presentation/layer_spec.rb +16 -20
- data/spec/unit/iiif/presentation/manifest_spec.rb +45 -48
- data/spec/unit/iiif/presentation/range_spec.rb +18 -22
- data/spec/unit/iiif/presentation/resource_spec.rb +3 -6
- data/spec/unit/iiif/presentation/sequence_spec.rb +58 -63
- data/spec/unit/iiif/presentation/shared_examples/abstract_resource_only_keys.rb +4 -10
- data/spec/unit/iiif/presentation/shared_examples/any_type_keys.rb +5 -9
- data/spec/unit/iiif/presentation/shared_examples/array_only_keys.rb +9 -17
- data/spec/unit/iiif/presentation/shared_examples/int_only_keys.rb +6 -14
- data/spec/unit/iiif/presentation/shared_examples/string_only_keys.rb +6 -13
- data/spec/unit/iiif/service_spec.rb +8 -13
- data/spec/unit/iiif/v3/abstract_resource_define_methods_for_spec.rb +39 -37
- data/spec/unit/iiif/v3/abstract_resource_spec.rb +124 -131
- data/spec/unit/iiif/v3/presentation/annotation_collection_spec.rb +14 -17
- data/spec/unit/iiif/v3/presentation/annotation_page_spec.rb +71 -69
- data/spec/unit/iiif/v3/presentation/annotation_spec.rb +249 -233
- data/spec/unit/iiif/v3/presentation/canvas_spec.rb +211 -193
- data/spec/unit/iiif/v3/presentation/choice_spec.rb +81 -77
- data/spec/unit/iiif/v3/presentation/collection_spec.rb +24 -29
- data/spec/unit/iiif/v3/presentation/image_resource_spec.rb +70 -71
- data/spec/unit/iiif/v3/presentation/manifest_spec.rb +248 -235
- data/spec/unit/iiif/v3/presentation/nav_place_spec.rb +249 -49
- data/spec/unit/iiif/v3/presentation/range_spec.rb +28 -29
- data/spec/unit/iiif/v3/presentation/resource_spec.rb +83 -82
- data/spec/unit/iiif/v3/presentation/sequence_spec.rb +125 -119
- data/spec/unit/iiif/v3/presentation/service_spec.rb +123 -124
- data/spec/unit/iiif/v3/presentation/shared_examples/abstract_resource_only_keys.rb +4 -8
- data/spec/unit/iiif/v3/presentation/shared_examples/any_type_keys.rb +5 -7
- data/spec/unit/iiif/v3/presentation/shared_examples/array_only_keys.rb +9 -13
- data/spec/unit/iiif/v3/presentation/shared_examples/hash_only_keys.rb +9 -13
- data/spec/unit/iiif/v3/presentation/shared_examples/int_only_keys.rb +6 -10
- data/spec/unit/iiif/v3/presentation/shared_examples/numeric_only_keys.rb +6 -10
- data/spec/unit/iiif/v3/presentation/shared_examples/string_only_keys.rb +6 -10
- data/spec/unit/iiif/v3/presentation/shared_examples/uri_only_keys.rb +9 -13
- metadata +26 -65
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
RSpec.describe IIIF::Service do
|
|
2
|
+
let(:fixtures_dir) { File.join(File.dirname(__FILE__), "../../fixtures") }
|
|
3
|
+
let(:manifest_from_spec_path) { File.join(fixtures_dir, "manifests/complete_from_spec.json") }
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
describe 'self.parse' do
|
|
7
|
-
it 'works from a file' do
|
|
5
|
+
describe "self.parse" do
|
|
6
|
+
it "works from a file" do
|
|
8
7
|
s = described_class.parse(manifest_from_spec_path)
|
|
9
|
-
expect(s[
|
|
8
|
+
expect(s["label"]).to eq "Book 1"
|
|
10
9
|
end
|
|
11
|
-
it
|
|
12
|
-
file = File.open(manifest_from_spec_path,
|
|
10
|
+
it "works from a string of JSON" do
|
|
11
|
+
file = File.open(manifest_from_spec_path, "rb")
|
|
13
12
|
json_string = file.read
|
|
14
13
|
file.close
|
|
15
14
|
s = described_class.parse(json_string)
|
|
16
|
-
expect(s[
|
|
15
|
+
expect(s["label"]).to eq "Book 1"
|
|
17
16
|
end
|
|
18
|
-
describe
|
|
19
|
-
it
|
|
17
|
+
describe "works from a hash" do
|
|
18
|
+
it "plain old" do
|
|
20
19
|
h = JSON.parse(IO.read(manifest_from_spec_path))
|
|
21
20
|
s = described_class.parse(h)
|
|
22
|
-
expect(s[
|
|
21
|
+
expect(s["label"]).to eq "Book 1"
|
|
23
22
|
end
|
|
24
|
-
it
|
|
23
|
+
it "IIIF::OrderedHash" do
|
|
25
24
|
h = JSON.parse(IO.read(manifest_from_spec_path))
|
|
26
25
|
oh = IIIF::OrderedHash[h]
|
|
27
26
|
s = described_class.parse(oh)
|
|
28
|
-
expect(s[
|
|
27
|
+
expect(s["label"]).to eq "Book 1"
|
|
29
28
|
end
|
|
30
29
|
end
|
|
31
|
-
it
|
|
30
|
+
it "turns camels to snakes" do
|
|
32
31
|
s = described_class.parse(manifest_from_spec_path)
|
|
33
|
-
expect(s.
|
|
34
|
-
expect(s.
|
|
32
|
+
expect(s.key?("see_also")).to be_truthy
|
|
33
|
+
expect(s.key?("seeAlso")).to be_falsey
|
|
35
34
|
end
|
|
36
35
|
end
|
|
37
36
|
|
|
38
|
-
describe
|
|
37
|
+
describe "self#from_ordered_hash" do
|
|
39
38
|
subject(:parsed) { described_class.from_ordered_hash(fixture) }
|
|
40
|
-
let(:fixture) {
|
|
39
|
+
let(:fixture) {
|
|
40
|
+
JSON.parse('{
|
|
41
41
|
"@context": "http://iiif.io/api/presentation/2/context.json",
|
|
42
42
|
"@id": "http://example.com/manifest",
|
|
43
43
|
"@type": "sc:Manifest",
|
|
@@ -84,33 +84,31 @@ RSpec.describe IIIF::Service do
|
|
|
84
84
|
]
|
|
85
85
|
}')
|
|
86
86
|
}
|
|
87
|
-
it
|
|
87
|
+
it "doesn't raise a NoMethodError when we check the keys" do
|
|
88
88
|
expect { parsed }.to_not raise_error
|
|
89
89
|
end
|
|
90
90
|
|
|
91
|
-
it
|
|
91
|
+
it "turns the fixture into a Manifest instance" do
|
|
92
92
|
expect(parsed).to be_a IIIF::Presentation::Manifest
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
it 'turns keys without "@type" into an OrderedHash' do
|
|
96
|
-
expect(parsed[
|
|
96
|
+
expect(parsed["some_other_thing"]).to be_a IIIF::OrderedHash
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
-
it
|
|
100
|
-
expect(parsed[
|
|
99
|
+
it "turns services into Services" do
|
|
100
|
+
expect(parsed["service"]).to be_a IIIF::Presentation::Service
|
|
101
101
|
end
|
|
102
102
|
|
|
103
|
-
it
|
|
104
|
-
fixture[
|
|
105
|
-
expect(parsed[
|
|
103
|
+
it "works with arrays of services" do
|
|
104
|
+
fixture["service"] = [fixture["service"]]
|
|
105
|
+
expect(parsed["service"].first).to be_a IIIF::Presentation::Service
|
|
106
106
|
end
|
|
107
107
|
|
|
108
|
-
it
|
|
109
|
-
fp =
|
|
110
|
-
File.
|
|
111
|
-
|
|
112
|
-
end
|
|
113
|
-
from_file = IIIF::Service.parse('/tmp/osullivan-spec.json')
|
|
108
|
+
it "round-trips" do
|
|
109
|
+
fp = "/tmp/osullivan-spec.json"
|
|
110
|
+
File.write(fp, parsed.to_json)
|
|
111
|
+
from_file = IIIF::Service.parse("/tmp/osullivan-spec.json")
|
|
114
112
|
File.delete(fp)
|
|
115
113
|
# is this sufficient?
|
|
116
114
|
expect(parsed.to_ordered_hash.to_a - from_file.to_ordered_hash.to_a).to eq []
|
|
@@ -118,86 +116,87 @@ RSpec.describe IIIF::Service do
|
|
|
118
116
|
end
|
|
119
117
|
|
|
120
118
|
it 'turns each memeber of "sequences" into an instance of Sequence' do
|
|
121
|
-
expect(parsed[
|
|
119
|
+
expect(parsed["sequences"]).to all be_a IIIF::Presentation::Sequence
|
|
122
120
|
end
|
|
123
121
|
|
|
124
|
-
it
|
|
125
|
-
parsed[
|
|
122
|
+
it "turns each member of sequences/canvaes in an instance of Canvas" do
|
|
123
|
+
parsed["sequences"].each do |s|
|
|
126
124
|
expect(s.canvases).to all be_a IIIF::Presentation::Canvas
|
|
127
125
|
end
|
|
128
126
|
end
|
|
129
127
|
|
|
130
|
-
it
|
|
131
|
-
expect(parsed.has_key?(
|
|
132
|
-
expect(parsed.has_key?(
|
|
128
|
+
it "turns the keys into snakes" do
|
|
129
|
+
expect(parsed.has_key?("seeAlso")).to be false
|
|
130
|
+
expect(parsed.has_key?("see_also")).to be true
|
|
133
131
|
end
|
|
134
132
|
|
|
135
|
-
it
|
|
136
|
-
expect(parsed[
|
|
133
|
+
it "copies over plain-old key-values" do
|
|
134
|
+
expect(parsed["label"]).to eq "My Manifest"
|
|
137
135
|
end
|
|
138
136
|
end
|
|
139
137
|
|
|
140
|
-
describe
|
|
141
|
-
let(:logo_uri) {
|
|
142
|
-
let(:within_uri) {
|
|
143
|
-
let(:see_also) {
|
|
144
|
-
|
|
145
|
-
describe
|
|
146
|
-
let(:extra_props) {
|
|
147
|
-
[
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
subject.keys.select { |k| k.start_with?('@') }.sort!
|
|
138
|
+
describe "#to_ordered_hash" do
|
|
139
|
+
let(:logo_uri) { "http://www.example.org/logos/institution1.jpg" }
|
|
140
|
+
let(:within_uri) { "http://www.example.org/collections/books/" }
|
|
141
|
+
let(:see_also) { "http://www.example.org/library/catalog/book1.xml" }
|
|
142
|
+
|
|
143
|
+
describe "it puts the json-ld keys at the top" do
|
|
144
|
+
let(:extra_props) {
|
|
145
|
+
[
|
|
146
|
+
["label", "foo"],
|
|
147
|
+
["logo", "http://example.com/logo.jpg"],
|
|
148
|
+
["within", "http://example.com/something"]
|
|
149
|
+
]
|
|
153
150
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
151
|
+
let(:sorted_ld_keys) {
|
|
152
|
+
subject.keys.select { |k| k.start_with?("@") }.sort!
|
|
153
|
+
}
|
|
154
|
+
before(:each) {
|
|
155
|
+
extra_props.reverse_each do |k, v|
|
|
156
|
+
subject.unshift(k, v)
|
|
157
157
|
end
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
it
|
|
161
|
-
(0..extra_props.length-1).each do |i|
|
|
160
|
+
it "by default" do
|
|
161
|
+
(0..extra_props.length - 1).each do |i|
|
|
162
162
|
expect(subject.keys[i]).to eq(extra_props[i][0])
|
|
163
163
|
end
|
|
164
164
|
oh = subject.to_ordered_hash
|
|
165
|
-
(0..sorted_ld_keys.length-1).each do |i|
|
|
165
|
+
(0..sorted_ld_keys.length - 1).each do |i|
|
|
166
166
|
expect(oh.keys[i]).to eq(sorted_ld_keys[i])
|
|
167
167
|
end
|
|
168
168
|
end
|
|
169
|
-
it
|
|
170
|
-
(0..extra_props.length-1).each do |i|
|
|
169
|
+
it "unless you say not to" do
|
|
170
|
+
(0..extra_props.length - 1).each do |i|
|
|
171
171
|
expect(subject.keys[i]).to eq(extra_props[i][0])
|
|
172
172
|
end
|
|
173
173
|
oh = subject.to_ordered_hash(sort_json_ld_keys: false)
|
|
174
|
-
(0..extra_props.length-1).each do |i|
|
|
174
|
+
(0..extra_props.length - 1).each do |i|
|
|
175
175
|
expect(oh.keys[i]).to eq(extra_props[i][0])
|
|
176
176
|
end
|
|
177
177
|
end
|
|
178
178
|
end
|
|
179
179
|
|
|
180
|
-
describe
|
|
181
|
-
it
|
|
182
|
-
subject[
|
|
183
|
-
subject[
|
|
180
|
+
describe "removes empty keys" do
|
|
181
|
+
it "if they're arrays" do
|
|
182
|
+
subject["logo"] = logo_uri
|
|
183
|
+
subject["within"] = []
|
|
184
184
|
ordered_hash = subject.to_ordered_hash
|
|
185
|
-
expect(ordered_hash.has_key?(
|
|
185
|
+
expect(ordered_hash.has_key?("within")).to be_falsey
|
|
186
186
|
end
|
|
187
|
-
it
|
|
188
|
-
subject[
|
|
189
|
-
subject[
|
|
187
|
+
it "if they're nil" do
|
|
188
|
+
subject["logo"] = logo_uri
|
|
189
|
+
subject["within"] = nil
|
|
190
190
|
ordered_hash = subject.to_ordered_hash
|
|
191
|
-
expect(ordered_hash.has_key?(
|
|
191
|
+
expect(ordered_hash.has_key?("within")).to be_falsey
|
|
192
192
|
end
|
|
193
193
|
end
|
|
194
194
|
|
|
195
|
-
it
|
|
196
|
-
subject[
|
|
197
|
-
subject[
|
|
195
|
+
it "converts snake_case keys to camelCase" do
|
|
196
|
+
subject["see_also"] = logo_uri
|
|
197
|
+
subject["within"] = within_uri
|
|
198
198
|
ordered_hash = subject.to_ordered_hash
|
|
199
|
-
expect(ordered_hash.
|
|
199
|
+
expect(ordered_hash.key?("seeAlso")).to be_truthy
|
|
200
200
|
end
|
|
201
201
|
end
|
|
202
|
-
|
|
203
202
|
end
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
1
|
+
require "active_support/inflector"
|
|
2
|
+
require "json"
|
|
3
3
|
|
|
4
4
|
describe IIIF::V3::AbstractResource do
|
|
5
|
+
let(:fixtures_dir) { File.join(File.dirname(__FILE__), "../../../fixtures") }
|
|
6
|
+
let(:manifest_from_spec_path) { File.join(fixtures_dir, "v3/manifests/complete_from_spec.json") }
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
describe 'self.parse' do
|
|
10
|
-
it 'works from a file' do
|
|
8
|
+
describe "self.parse" do
|
|
9
|
+
it "works from a file" do
|
|
11
10
|
s = described_class.parse(manifest_from_spec_path)
|
|
12
|
-
expect(s[
|
|
11
|
+
expect(s["label"]["en"]).to include "Book 1"
|
|
13
12
|
end
|
|
14
|
-
it
|
|
15
|
-
file = File.open(manifest_from_spec_path,
|
|
13
|
+
it "works from a string of JSON" do
|
|
14
|
+
file = File.open(manifest_from_spec_path, "rb")
|
|
16
15
|
json_string = file.read
|
|
17
16
|
file.close
|
|
18
17
|
s = described_class.parse(json_string)
|
|
19
|
-
expect(s[
|
|
18
|
+
expect(s["label"]["en"]).to include "Book 1"
|
|
20
19
|
end
|
|
21
|
-
describe
|
|
22
|
-
it
|
|
20
|
+
describe "works from a hash" do
|
|
21
|
+
it "plain old" do
|
|
23
22
|
h = JSON.parse(IO.read(manifest_from_spec_path))
|
|
24
23
|
s = described_class.parse(h)
|
|
25
|
-
expect(s[
|
|
24
|
+
expect(s["label"]["en"]).to include "Book 1"
|
|
26
25
|
end
|
|
27
|
-
it
|
|
26
|
+
it "IIIF::OrderedHash" do
|
|
28
27
|
h = JSON.parse(IO.read(manifest_from_spec_path))
|
|
29
28
|
oh = IIIF::OrderedHash[h]
|
|
30
29
|
s = described_class.parse(oh)
|
|
31
|
-
expect(s[
|
|
30
|
+
expect(s["label"]["en"]).to include "Book 1"
|
|
32
31
|
end
|
|
33
32
|
end
|
|
34
|
-
it
|
|
33
|
+
it "turns camels to snakes" do
|
|
35
34
|
s = described_class.parse(manifest_from_spec_path)
|
|
36
|
-
expect(s.
|
|
37
|
-
expect(s.
|
|
35
|
+
expect(s.key?("see_also")).to be_truthy
|
|
36
|
+
expect(s.key?("seeAlso")).to be_falsey
|
|
38
37
|
end
|
|
39
38
|
end
|
|
40
39
|
|
|
41
|
-
describe
|
|
42
|
-
let(:fixture) {
|
|
40
|
+
describe "self#from_ordered_hash" do
|
|
41
|
+
let(:fixture) {
|
|
42
|
+
JSON.parse('{
|
|
43
43
|
"@context": [
|
|
44
44
|
"http://iiif.io/api/presentation/3/context.json",
|
|
45
45
|
"http://www.w3.org/ns/anno.jsonld"
|
|
@@ -81,10 +81,10 @@ describe IIIF::V3::AbstractResource do
|
|
|
81
81
|
]
|
|
82
82
|
}')
|
|
83
83
|
}
|
|
84
|
-
it
|
|
84
|
+
it "doesn't raise a NoMethodError when we check the keys" do
|
|
85
85
|
expect { described_class.from_ordered_hash(fixture) }.to_not raise_error
|
|
86
86
|
end
|
|
87
|
-
it
|
|
87
|
+
it "turns the fixture into a Manifest instance" do
|
|
88
88
|
expected_klass = IIIF::V3::Presentation::Manifest
|
|
89
89
|
parsed = described_class.from_ordered_hash(fixture)
|
|
90
90
|
expect(parsed.class).to be expected_klass
|
|
@@ -92,22 +92,20 @@ describe IIIF::V3::AbstractResource do
|
|
|
92
92
|
it 'turns keys without "type" into an OrderedHash' do
|
|
93
93
|
expected_klass = IIIF::OrderedHash
|
|
94
94
|
parsed = described_class.from_ordered_hash(fixture)
|
|
95
|
-
expect(parsed[
|
|
95
|
+
expect(parsed["some_other_thing"].class).to be expected_klass
|
|
96
96
|
end
|
|
97
97
|
|
|
98
|
-
it
|
|
98
|
+
it "turns services into Services" do
|
|
99
99
|
expected_klass = IIIF::V3::Presentation::Service
|
|
100
100
|
parsed = described_class.from_ordered_hash(fixture)
|
|
101
|
-
expect(parsed[
|
|
101
|
+
expect(parsed["service"].map(&:class).uniq).to contain_exactly expected_klass
|
|
102
102
|
end
|
|
103
103
|
|
|
104
|
-
it
|
|
105
|
-
fp =
|
|
104
|
+
it "round-trips" do
|
|
105
|
+
fp = "/tmp/osullivan-spec.json"
|
|
106
106
|
parsed = described_class.from_ordered_hash(fixture)
|
|
107
|
-
File.
|
|
108
|
-
|
|
109
|
-
end
|
|
110
|
-
from_file = IIIF::V3::Presentation::Service.parse('/tmp/osullivan-spec.json')
|
|
107
|
+
File.write(fp, parsed.to_json)
|
|
108
|
+
from_file = IIIF::V3::Presentation::Service.parse("/tmp/osullivan-spec.json")
|
|
111
109
|
File.delete(fp)
|
|
112
110
|
# is this sufficient?
|
|
113
111
|
expect(parsed.to_ordered_hash.to_a - from_file.to_ordered_hash.to_a).to eq []
|
|
@@ -115,91 +113,92 @@ describe IIIF::V3::AbstractResource do
|
|
|
115
113
|
end
|
|
116
114
|
it 'turns each member of "items" into an instance of Sequence' do
|
|
117
115
|
parsed = described_class.from_ordered_hash(fixture)
|
|
118
|
-
parsed[
|
|
116
|
+
parsed["items"].each do |s|
|
|
119
117
|
expect(s.class).to be IIIF::V3::Presentation::Canvas
|
|
120
118
|
end
|
|
121
119
|
end
|
|
122
|
-
it
|
|
120
|
+
it "turns each member of sequences/items into an instance of Canvas" do
|
|
123
121
|
parsed = described_class.from_ordered_hash(fixture)
|
|
124
|
-
parsed[
|
|
122
|
+
parsed["items"].each do |s|
|
|
125
123
|
s.items.each do |c|
|
|
126
124
|
expect(c.class).to be IIIF::V3::Presentation::Canvas
|
|
127
125
|
end
|
|
128
126
|
end
|
|
129
127
|
end
|
|
130
|
-
it
|
|
131
|
-
expect(described_class.from_ordered_hash(fixture).has_key?(
|
|
132
|
-
expect(described_class.from_ordered_hash(fixture).has_key?(
|
|
128
|
+
it "turns the keys into snakes" do
|
|
129
|
+
expect(described_class.from_ordered_hash(fixture).has_key?("seeAlso")).to be_falsey
|
|
130
|
+
expect(described_class.from_ordered_hash(fixture).has_key?("see_also")).to be_truthy
|
|
133
131
|
end
|
|
134
|
-
it
|
|
132
|
+
it "copies over plain-old key-values" do
|
|
135
133
|
parsed = described_class.from_ordered_hash(fixture)
|
|
136
|
-
expect(parsed[
|
|
134
|
+
expect(parsed["label"]).to eq "My Manifest"
|
|
137
135
|
end
|
|
138
136
|
end
|
|
139
137
|
|
|
140
|
-
describe
|
|
141
|
-
let(:logo_uri) {
|
|
142
|
-
let(:within_uri) {
|
|
143
|
-
let(:see_also) {
|
|
138
|
+
describe "#to_ordered_hash" do
|
|
139
|
+
let(:logo_uri) { "http://www.example.org/logos/institution1.jpg" }
|
|
140
|
+
let(:within_uri) { "http://www.example.org/collections/books/" }
|
|
141
|
+
let(:see_also) { "http://www.example.org/library/catalog/book1.xml" }
|
|
144
142
|
# NOTE: Using Service to test, as we can't initialize the abstract class
|
|
145
143
|
let(:instantiated_class) { IIIF::V3::Presentation::Service.new }
|
|
146
144
|
|
|
147
|
-
describe
|
|
148
|
-
let(:extra_props) {
|
|
149
|
-
[
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
145
|
+
describe "it puts the json-ld keys at the top" do
|
|
146
|
+
let(:extra_props) {
|
|
147
|
+
[
|
|
148
|
+
["label", "foo"],
|
|
149
|
+
["logo", "http://example.com/logo.jpg"],
|
|
150
|
+
["within", "http://example.com/something"]
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
153
|
let(:sorted_ld_keys) {
|
|
154
|
-
instantiated_class.keys.select { |k| k.start_with?(
|
|
154
|
+
instantiated_class.keys.select { |k| k.start_with?("@") }.sort!
|
|
155
155
|
}
|
|
156
156
|
before(:each) {
|
|
157
|
-
extra_props.
|
|
158
|
-
instantiated_class.unshift(k,v)
|
|
157
|
+
extra_props.reverse_each do |k, v|
|
|
158
|
+
instantiated_class.unshift(k, v)
|
|
159
159
|
end
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
it
|
|
163
|
-
(0..extra_props.length-1).each do |i|
|
|
162
|
+
it "by default" do
|
|
163
|
+
(0..extra_props.length - 1).each do |i|
|
|
164
164
|
expect(instantiated_class.keys[i]).to eq(extra_props[i][0])
|
|
165
165
|
end
|
|
166
166
|
oh = instantiated_class.to_ordered_hash
|
|
167
|
-
(0..sorted_ld_keys.length-1).each do |i|
|
|
167
|
+
(0..sorted_ld_keys.length - 1).each do |i|
|
|
168
168
|
expect(oh.keys[i]).to eq(sorted_ld_keys[i])
|
|
169
169
|
end
|
|
170
170
|
end
|
|
171
|
-
it
|
|
172
|
-
(0..extra_props.length-1).each do |i|
|
|
171
|
+
it "unless you say not to" do
|
|
172
|
+
(0..extra_props.length - 1).each do |i|
|
|
173
173
|
expect(instantiated_class.keys[i]).to eq(extra_props[i][0])
|
|
174
174
|
end
|
|
175
175
|
oh = instantiated_class.to_ordered_hash(sort_json_ld_keys: false)
|
|
176
|
-
(0..extra_props.length-1).each do |i|
|
|
176
|
+
(0..extra_props.length - 1).each do |i|
|
|
177
177
|
expect(oh.keys[i]).to eq(extra_props[i][0])
|
|
178
178
|
end
|
|
179
179
|
end
|
|
180
180
|
end
|
|
181
181
|
|
|
182
|
-
describe
|
|
183
|
-
it
|
|
184
|
-
instantiated_class[
|
|
185
|
-
instantiated_class[
|
|
182
|
+
describe "removes empty keys" do
|
|
183
|
+
it "if they're arrays" do
|
|
184
|
+
instantiated_class["logo"] = logo_uri
|
|
185
|
+
instantiated_class["within"] = []
|
|
186
186
|
ordered_hash = instantiated_class.to_ordered_hash
|
|
187
|
-
expect(ordered_hash.has_key?(
|
|
187
|
+
expect(ordered_hash.has_key?("within")).to be_falsey
|
|
188
188
|
end
|
|
189
|
-
it
|
|
190
|
-
instantiated_class[
|
|
191
|
-
instantiated_class[
|
|
189
|
+
it "if they're nil" do
|
|
190
|
+
instantiated_class["logo"] = logo_uri
|
|
191
|
+
instantiated_class["within"] = nil
|
|
192
192
|
ordered_hash = instantiated_class.to_ordered_hash
|
|
193
|
-
expect(ordered_hash.has_key?(
|
|
193
|
+
expect(ordered_hash.has_key?("within")).to be_falsey
|
|
194
194
|
end
|
|
195
195
|
end
|
|
196
196
|
|
|
197
|
-
it
|
|
198
|
-
instantiated_class[
|
|
199
|
-
instantiated_class[
|
|
197
|
+
it "converts snake_case keys to camelCase" do
|
|
198
|
+
instantiated_class["see_also"] = logo_uri
|
|
199
|
+
instantiated_class["within"] = within_uri
|
|
200
200
|
ordered_hash = instantiated_class.to_ordered_hash
|
|
201
|
-
expect(ordered_hash.
|
|
201
|
+
expect(ordered_hash.key?("seeAlso")).to be_truthy
|
|
202
202
|
end
|
|
203
203
|
end
|
|
204
|
-
|
|
205
204
|
end
|