Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add viewingDirection as optional data value on manifest, fixes #12 #13

Merged
merged 5 commits into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion iiif_manifest.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Gem::Specification.new do |spec|
spec.add_dependency 'iiif-presentation', '~> 0.2.0'

spec.add_development_dependency 'bundler', '~> 1.11'
spec.add_development_dependency 'pry-byebug'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'rubocop-rspec'
spec.add_development_dependency 'pry-byebug'
end
7 changes: 7 additions & 0 deletions lib/iiif_manifest/manifest_builder/record_property_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@ def initialize(record)
@record = record
end

# rubocop:disable Metrics/AbcSize
def apply(manifest)
manifest['@id'] = record.manifest_url.to_s
manifest.label = record.to_s
manifest.description = record.description
manifest.viewing_hint = viewing_hint if viewing_hint.present?
manifest.viewing_direction = viewing_direction if viewing_direction.present?
manifest.metadata = record.manifest_metadata if valid_metadata?
manifest
end
# rubocop:enable Metrics/AbcSize

private

def viewing_hint
(record.respond_to?(:viewing_hint) && record.send(:viewing_hint))
end

def viewing_direction
(record.respond_to?(:viewing_direction) && record.send(:viewing_direction))
end

# Validate manifest_metadata against the IIIF spec format for metadata
#
# @return [Boolean]
Expand Down
23 changes: 18 additions & 5 deletions spec/lib/iiif_manifest/manifest_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def display_image
end
end

context 'where there is a no sequence_rendering method' do
context 'when there is a no sequence_rendering method' do
let(:file_presenter) { DisplayImagePresenter.new }

it 'does not have a rendering on the sequence' do
Expand All @@ -120,7 +120,7 @@ def display_image
end
end

context 'where there is a sequence_rendering method' do
context 'when there is a sequence_rendering method' do
let(:file_presenter) { DisplayImagePresenter.new }

before do
Expand Down Expand Up @@ -163,7 +163,7 @@ def sequence_rendering
end
end

context 'where there is a no manifest_metadata method' do
context 'when there is no manifest_metadata method' do
let(:file_presenter) { DisplayImagePresenter.new }

it 'does not have a metadata element' do
Expand All @@ -173,7 +173,7 @@ def sequence_rendering
end
end

context 'where there is a manifest_metadata method' do
context 'when there is a manifest_metadata method' do
let(:metadata) { [{ 'label' => 'Title', 'value' => 'Title of the Item' }] }

it 'has metadata' do
Expand All @@ -183,7 +183,7 @@ def sequence_rendering
end
end

context 'where there is a manifest_metadata method with invalid data' do
context 'when there is a manifest_metadata method with invalid data' do
let(:metadata) { 'invalid data' }

it 'has no metadata' do
Expand Down Expand Up @@ -236,5 +236,18 @@ def sequence_rendering
expect(result['sequences'].first['canvases'].length).to eq 2
end
end

context 'when there is no viewing_direction method' do
it 'does not have a viewingDirection element' do
expect(result['viewingDirection']).to eq nil
end
end

context 'when there is a viewing_direction method' do
it 'has a viewingDirection' do
allow(book_presenter).to receive(:viewing_direction).and_return('right-to-left')
expect(result.viewingDirection).to eq 'right-to-left'
end
end
end
end