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