Skip to content

Commit

Permalink
Add canvas reference to all root ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
masaball committed Nov 6, 2023
1 parent d50e19c commit 0eecfd2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
8 changes: 1 addition & 7 deletions app/models/iiif_canvas_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ def structure_to_iiif_range
def root_to_iiif_range(root_node)
range = div_to_iiif_range(root_node)

if only_empty_descendants?(root_node)
range.items.prepend(IiifCanvasPresenter.new(master_file: master_file, stream_info: stream_info, media_fragment: "t=0,#{stream_info[:duration]}"))
end
range.items.prepend(IiifCanvasPresenter.new(master_file: master_file, stream_info: stream_info, media_fragment: "t=0,#{stream_info[:duration]}"))

return range
end
Expand Down Expand Up @@ -171,10 +169,6 @@ def span_to_iiif_range(span_node)
)
end

def only_empty_descendants?(node)
node.xpath('.//Span').empty?
end

FLOAT_PATTERN = Regexp.new(/^\d+([.]\d*)?$/).freeze

def parse_hour_min_sec(s)
Expand Down
44 changes: 24 additions & 20 deletions spec/models/iiif_canvas_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,17 @@
master_file.structuralMetadata.content = structure_xml
end

it 'converts stored xml into IIIF ranges' do
it 'converts stored xml into IIIF ranges with canvas reference in root range' do
expect(subject.label.to_s).to eq '{"none"=>["Test"]}'
expect(subject.items.size).to eq 1
expect(subject.items.first.label.to_s).to eq '{"none"=>["Div 1"]}'
expect(subject.items.first.items.size).to eq 1
expect(subject.items.first.items.first.label.to_s).to eq '{"none"=>["Span 1"]}'
expect(subject.items.first.items.first.items.size).to eq 1
expect(subject.items.first.items.first.items.first).to be_a IiifCanvasPresenter
expect(subject.items.first.items.first.items.first.media_fragment).to eq 't=0.0,1.235'
expect(subject.items.size).to eq 2
expect(subject.items.first).to be_a IiifCanvasPresenter
expect(subject.items.first.media_fragment).to eq "t=0,#{master_file.duration.to_f/1000}"
expect(subject.items.second.label.to_s).to eq '{"none"=>["Div 1"]}'
expect(subject.items.second.items.size).to eq 1
expect(subject.items.second.items.first.label.to_s).to eq '{"none"=>["Span 1"]}'
expect(subject.items.second.items.first.items.size).to eq 1
expect(subject.items.second.items.first.items.first).to be_a IiifCanvasPresenter
expect(subject.items.second.items.first.items.first.media_fragment).to eq 't=0.0,1.235'
end

context 'with no structural metadata' do
Expand Down Expand Up @@ -117,19 +119,21 @@
context 'with spans' do
let(:structure_xml) { '<?xml version="1.0"?><Item label="Test"><Div label="Div 1"><Div label="Div 2"><Div label="Div 3"/></Div><Span label="Span 1" begin="00:00:00.000" end="00:00:01.235"/></Div></Item>' }

it 'does not generate a canvas reference in the root range' do
it 'generates a canvas reference in the root range' do
expect(subject.label.to_s).to eq '{"none"=>["Test"]}'
expect(subject.items.size).to eq 1
expect(subject.items.first.label.to_s).to eq '{"none"=>["Div 1"]}'
expect(subject.items.first.items.size).to eq 2
expect(subject.items.first.items.first.label.to_s).to eq '{"none"=>["Div 2"]}'
expect(subject.items.first.items.first.items.size).to eq 1
expect(subject.items.first.items.first.items.first.label.to_s).to eq '{"none"=>["Div 3"]}'
expect(subject.items.first.items.first.items.first.items.size).to eq 0
expect(subject.items.first.items.second.label.to_s).to eq '{"none"=>["Span 1"]}'
expect(subject.items.first.items.second.items.size).to eq 1
expect(subject.items.first.items.second.items.first).to be_a IiifCanvasPresenter
expect(subject.items.first.items.second.items.first.media_fragment).to eq 't=0.0,1.235'
expect(subject.items.size).to eq 2
expect(subject.items.first).to be_a IiifCanvasPresenter
expect(subject.items.first.media_fragment).to eq "t=0,#{master_file.duration.to_f/1000}"
expect(subject.items.second.label.to_s).to eq '{"none"=>["Div 1"]}'
expect(subject.items.second.items.size).to eq 2
expect(subject.items.second.items.first.label.to_s).to eq '{"none"=>["Div 2"]}'
expect(subject.items.second.items.first.items.size).to eq 1
expect(subject.items.second.items.first.items.first.label.to_s).to eq '{"none"=>["Div 3"]}'
expect(subject.items.second.items.first.items.first.items.size).to eq 0
expect(subject.items.second.items.second.label.to_s).to eq '{"none"=>["Span 1"]}'
expect(subject.items.second.items.second.items.size).to eq 1
expect(subject.items.second.items.second.items.first).to be_a IiifCanvasPresenter
expect(subject.items.second.items.second.items.first.media_fragment).to eq 't=0.0,1.235'
end
end
end
Expand Down

0 comments on commit 0eecfd2

Please sign in to comment.