Skip to content

Commit

Permalink
v3 canvas: relax requirement for extent info
Browse files Browse the repository at this point in the history
  • Loading branch information
ndushay committed Jul 19, 2017
1 parent f435913 commit ef2adb8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 9 additions & 5 deletions lib/iiif/v3/presentation/canvas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,18 @@ def validate
# It may have width, height and duration.""
height = self['height']
width = self['width']
extent_err_msg = "#{self.class} must have (a height and a width) and/or a duration"
if (!!height ^ !!width) # this is an exclusive or: forces height and width to boolean
extent_err_msg = "#{self.class} requires both height and width or neither"
raise IIIF::V3::Presentation::IllegalValueError, extent_err_msg
end
duration = self['duration']
unless (height && width) || duration
raise IIIF::V3::Presentation::IllegalValueError, extent_err_msg
end
# NOTE: relaxing requirement for (exactly one width and one height, and/or exactly one duration)
# as Stanford has objects (such as txt files) for which this makes no sense
# (see sul-dlss/purl/issues/169)
# duration = self['duration']
# unless (height && width) || duration
# extent_err_msg = "#{self.class} must have (a height and a width) and/or a duration"
# raise IIIF::V3::Presentation::IllegalValueError, extent_err_msg
# end

# TODO: Content must not be associated with space or time outside of the Canvas’s dimensions,
# such as at coordinates below 0,0, greater than the height or width, before 0 seconds, or after the duration.
Expand Down
6 changes: 5 additions & 1 deletion spec/unit/iiif/v3/presentation/canvas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def initialize(hsh={})
expect { subject.validate }.to raise_error(IIIF::V3::Presentation::IllegalValueError, exp_id_err_msg)
end

let(:exp_extent_err_msg) { "#{described_class} must have (a height and a width) and/or a duration" }
# let(:exp_extent_err_msg) { "#{described_class} must have (a height and a width) and/or a duration" }
# (see sul-dlss/purl/issues/169)
let(:exp_extent_err_msg) { "#{described_class} requires both height and width or neither" }
it 'raises an IllegalValueError if height is a string' do
subject['height'] = 'foo'
expect { subject.validate }.to raise_error(IIIF::V3::Presentation::IllegalValueError, exp_extent_err_msg)
Expand All @@ -90,6 +92,8 @@ def initialize(hsh={})
expect { subject.validate }.to raise_error(IIIF::V3::Presentation::IllegalValueError, exp_extent_err_msg)
end
it 'raises an IllegalValueError if no width, height or duration' do
# (see sul-dlss/purl/issues/169)
skip('while this is in the current v3 spec, it does not make sense for some content (e.g. txt files)')
expect { subject.validate }.to raise_error(IIIF::V3::Presentation::IllegalValueError, exp_extent_err_msg)
end
it 'allows width, height and duration' do
Expand Down

0 comments on commit ef2adb8

Please sign in to comment.