Skip to content

Commit

Permalink
v3 manifest: improve specificity, validation and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ndushay committed Jul 17, 2017
1 parent 8a58402 commit a596828
Show file tree
Hide file tree
Showing 3 changed files with 374 additions and 71 deletions.
59 changes: 53 additions & 6 deletions lib/iiif/v3/presentation/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@ module V3
module Presentation
class Manifest < IIIF::V3::AbstractResource

TYPE = 'Manifest'
TYPE = 'Manifest'.freeze

def required_keys
super + %w{ id label }
super + %w{ id label items }
end

def prohibited_keys
super + CONTENT_RESOURCE_PROPERTIES + PAGING_PROPERTIES + %w{ start_canvas content_annotation }
end

def uri_only_keys
super + %w{ id }
end

def array_only_keys
super + %w{ sequences structures }
super + %w{ items structures }
end

def legal_viewing_hint_values
%w{ individuals paged continuous auto-advance none }
%w{ individuals paged continuous auto-advance }
end

def initialize(hsh={})
Expand All @@ -23,8 +31,47 @@ def initialize(hsh={})
end

def validate
super
# TODO: check types of sequences and structure members
super # also checks navDate format

unless self['id'] =~ /^https?:/
err_msg = "id must be an http(s) URI for #{self.class}"
raise IIIF::V3::Presentation::IllegalValueError, err_msg
end

unless self['items'].size >= 1
m = 'The items list must have at least one entry (and it must be a IIIF::V3::Presentation::Sequence)'
raise IIIF::V3::Presentation::MissingRequiredKeyError, m
end

unless self['items'].all? { |entry| entry.instance_of?(IIIF::V3::Presentation::Sequence) }
m = 'All entries in the items list must be a IIIF::V3::Presentation::Sequence'
raise IIIF::V3::Presentation::IllegalValueError, m
end

default_sequence = self['items'].first
unless default_sequence['items'] && default_sequence['items'].size >=1 &&
default_sequence['items'].all? { |entry| entry.instance_of?(IIIF::V3::Presentation::Canvas) }
m = 'The default Sequence (the first entry of "items") must be written out in full within the Manifest file'
raise IIIF::V3::Presentation::IllegalValueError, m
end

if self['items'].size > 1
unless self['items'].all? { |entry| entry['label'] }
m = 'If there are multiple Sequences in a manifest then they must each have at least one label'
raise IIIF::V3::Presentation::IllegalValueError, m
end
end

# TODO: when embedding a sequence without any extensions within a manifest, the sequence must not have the @context field.

# TODO: AnnotationLists must not be embedded within the manifest

if self['structures']
unless self['structures'].all? { |entry| entry.instance_of?(IIIF::V3::Presentation::Range)}
m = 'All entries in the structures list must be a IIIF::V3::Presentation::Range'
raise IIIF::V3::Presentation::IllegalValueError, m
end
end
end
end
end
Expand Down
14 changes: 6 additions & 8 deletions spec/integration/iiif/v3/abstract_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"id": "http://www.example.org/library/catalog/book1.marc",
"format": "application/marc"
},
"sequences": [
"items": [
{
"id":"http://www.example.org/iiif/book1/sequence/normal",
"type": "Sequence",
Expand Down Expand Up @@ -121,16 +121,15 @@
expect(parsed.to_ordered_hash.to_a - from_file.to_ordered_hash.to_a).to eq []
expect(from_file.to_ordered_hash.to_a - parsed.to_ordered_hash.to_a).to eq []
end
it 'turns each member of "sequences" into an instance of Sequence' do
expected_klass = IIIF::V3::Presentation::Sequence
it 'turns each member of "items" into an instance of Sequence' do
parsed = described_class.from_ordered_hash(fixture)
parsed['sequences'].each do |s|
expect(s.class).to be expected_klass
parsed['items'].each do |s|
expect(s.class).to be IIIF::V3::Presentation::Sequence
end
end
it 'turns each member of items into an instance of Canvas' do
it 'turns each member of sequences/items into an instance of Canvas' do
parsed = described_class.from_ordered_hash(fixture)
parsed['sequences'].each do |s|
parsed['items'].each do |s|
s.items.each do |c|
expect(c.class).to be IIIF::V3::Presentation::Canvas
end
Expand All @@ -144,7 +143,6 @@
parsed = described_class.from_ordered_hash(fixture)
expect(parsed['label']).to eq 'My Manifest'
end

end

describe '#to_ordered_hash' do
Expand Down
Loading

0 comments on commit a596828

Please sign in to comment.