iiif_manifest 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -0
  3. data/.rspec +0 -0
  4. data/.rubocop.yml +3 -0
  5. data/.rubocop_todo.yml +36 -0
  6. data/.travis.yml +0 -0
  7. data/CODE_OF_CONDUCT.md +0 -0
  8. data/Gemfile +0 -0
  9. data/LICENSE +0 -0
  10. data/README.md +27 -10
  11. data/Rakefile +0 -0
  12. data/iiif_manifest.gemspec +2 -1
  13. data/lib/iiif_manifest.rb +1 -0
  14. data/lib/iiif_manifest/display_image.rb +0 -0
  15. data/lib/iiif_manifest/iiif_collection.rb +6 -4
  16. data/lib/iiif_manifest/iiif_endpoint.rb +0 -0
  17. data/lib/iiif_manifest/manifest_builder.rb +6 -6
  18. data/lib/iiif_manifest/manifest_builder/canvas_builder.rb +12 -12
  19. data/lib/iiif_manifest/manifest_builder/canvas_builder_factory.rb +3 -3
  20. data/lib/iiif_manifest/manifest_builder/child_manifest_builder_factory.rb +0 -0
  21. data/lib/iiif_manifest/manifest_builder/composite_builder.rb +0 -0
  22. data/lib/iiif_manifest/manifest_builder/composite_builder_factory.rb +0 -0
  23. data/lib/iiif_manifest/manifest_builder/deep_canvas_builder_factory.rb +6 -6
  24. data/lib/iiif_manifest/manifest_builder/iiif_service.rb +0 -0
  25. data/lib/iiif_manifest/manifest_builder/image_builder.rb +9 -9
  26. data/lib/iiif_manifest/manifest_builder/image_service_builder.rb +3 -3
  27. data/lib/iiif_manifest/manifest_builder/record_property_builder.rb +50 -51
  28. data/lib/iiif_manifest/manifest_builder/resource_builder.rb +9 -9
  29. data/lib/iiif_manifest/manifest_builder/sequence_builder.rb +19 -19
  30. data/lib/iiif_manifest/manifest_builder/structure_builder.rb +0 -0
  31. data/lib/iiif_manifest/manifest_factory.rb +3 -3
  32. data/lib/iiif_manifest/manifest_service_locator.rb +0 -0
  33. data/lib/iiif_manifest/v3.rb +13 -0
  34. data/lib/iiif_manifest/v3/display_content.rb +17 -0
  35. data/lib/iiif_manifest/v3/manifest_builder.rb +61 -0
  36. data/lib/iiif_manifest/v3/manifest_builder/body_builder.rb +48 -0
  37. data/lib/iiif_manifest/v3/manifest_builder/canvas_builder.rb +77 -0
  38. data/lib/iiif_manifest/v3/manifest_builder/choice_builder.rb +47 -0
  39. data/lib/iiif_manifest/v3/manifest_builder/content_builder.rb +38 -0
  40. data/lib/iiif_manifest/v3/manifest_builder/iiif_service.rb +235 -0
  41. data/lib/iiif_manifest/v3/manifest_builder/image_service_builder.rb +35 -0
  42. data/lib/iiif_manifest/v3/manifest_builder/record_property_builder.rb +97 -0
  43. data/lib/iiif_manifest/v3/manifest_builder/structure_builder.rb +87 -0
  44. data/lib/iiif_manifest/v3/manifest_factory.rb +38 -0
  45. data/lib/iiif_manifest/v3/manifest_service_locator.rb +148 -0
  46. data/lib/iiif_manifest/version.rb +1 -1
  47. metadata +29 -2
@@ -0,0 +1,35 @@
1
+ module IIIFManifest
2
+ module V3
3
+ class ManifestBuilder
4
+ class ImageServiceBuilder
5
+ attr_reader :iiif_endpoint, :iiif_service_factory
6
+ def initialize(iiif_endpoint, iiif_service_factory:)
7
+ @iiif_endpoint = iiif_endpoint
8
+ @iiif_service_factory = iiif_service_factory
9
+ end
10
+
11
+ def apply(resource)
12
+ service['id'] = iiif_endpoint.url
13
+ service['profile'] = iiif_endpoint.profile
14
+ service['type'] = determine_type(iiif_endpoint.context)
15
+ resource.service = [service]
16
+ end
17
+
18
+ private
19
+
20
+ def determine_type(context)
21
+ case context
22
+ when 'http://iiif.io/api/image/1/context.json'
23
+ 'ImageService1'
24
+ when 'http://iiif.io/api/image/2/context.json'
25
+ 'ImageService2'
26
+ end
27
+ end
28
+
29
+ def service
30
+ @service ||= iiif_service_factory.new
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,97 @@
1
+ module IIIFManifest
2
+ module V3
3
+ class ManifestBuilder
4
+ class RecordPropertyBuilder < ::IIIFManifest::ManifestBuilder::RecordPropertyBuilder
5
+ attr_reader :canvas_builder_factory
6
+ def initialize(record,
7
+ iiif_search_service_factory:,
8
+ iiif_autocomplete_service_factory:,
9
+ canvas_builder_factory:)
10
+ super(record,
11
+ iiif_search_service_factory: iiif_search_service_factory,
12
+ iiif_autocomplete_service_factory: iiif_autocomplete_service_factory)
13
+ @canvas_builder_factory = canvas_builder_factory
14
+ end
15
+
16
+ def apply(manifest)
17
+ setup_manifest_from_record(manifest, record)
18
+ # Build the items array
19
+ canvas_builder.apply(manifest.items)
20
+ manifest
21
+ end
22
+
23
+ def populate_rendering
24
+ if record.respond_to?(:sequence_rendering)
25
+ record.sequence_rendering.collect do |rendering|
26
+ sequence_rendering = rendering.to_h.except('@id', 'label')
27
+ sequence_rendering['id'] = rendering['@id']
28
+ if rendering['label'].present?
29
+ sequence_rendering['label'] = ManifestBuilder.language_map(rendering['label'])
30
+ end
31
+ sequence_rendering
32
+ end
33
+ else
34
+ []
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def canvas_builder
41
+ canvas_builder_factory.from(record)
42
+ end
43
+
44
+ def setup_manifest_from_record(manifest, record)
45
+ manifest['id'] = record.manifest_url.to_s
46
+ manifest.label = ManifestBuilder.language_map(record.to_s) if record.to_s.present?
47
+ manifest.summary = ManifestBuilder.language_map(record.description) if record.try(:description).present?
48
+ manifest.behavior = viewing_hint if viewing_hint.present?
49
+ manifest.metadata = metadata_from_record(record)
50
+ manifest.viewing_direction = viewing_direction if viewing_direction.present?
51
+ manifest.service = services if search_service.present?
52
+ manifest.rendering = populate_rendering
53
+ end
54
+
55
+ def metadata_from_record(record)
56
+ if valid_v3_metadata?
57
+ record.manifest_metadata
58
+ elsif valid_metadata?
59
+ transform_metadata(record.manifest_metadata)
60
+ end
61
+ end
62
+
63
+ # Validate manifest_metadata against the IIIF spec format for metadata
64
+ #
65
+ # @return [Boolean]
66
+ def valid_v3_metadata?
67
+ return false unless record.respond_to?(:manifest_metadata)
68
+ metadata = record.manifest_metadata
69
+ valid_v3_metadata_fields?(metadata)
70
+ end
71
+
72
+ # Manifest metadata must be an array containing hashes
73
+ #
74
+ # @param metadata [Array<Hash>] a list of metadata with label and value as required keys for each entry
75
+ # @return [Boolean]
76
+ def valid_v3_metadata_fields?(metadata)
77
+ metadata.is_a?(Array) && metadata.all? do |metadata_field|
78
+ metadata_field.is_a?(Hash) &&
79
+ ManifestBuilder.valid_language_map?(metadata_field['label']) &&
80
+ ManifestBuilder.valid_language_map?(metadata_field['value'])
81
+ end
82
+ end
83
+
84
+ def transform_metadata(metadata)
85
+ metadata.collect { |field| transform_field(field) }
86
+ end
87
+
88
+ def transform_field(field)
89
+ metadata_field = {}
90
+ metadata_field['label'] = ManifestBuilder.language_map(field['label'])
91
+ metadata_field['value'] = ManifestBuilder.language_map(field['value'])
92
+ metadata_field
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,87 @@
1
+ module IIIFManifest
2
+ module V3
3
+ class ManifestBuilder
4
+ class StructureBuilder < ::IIIFManifest::ManifestBuilder::StructureBuilder
5
+ def range_builder(top_range)
6
+ RangeBuilder.new(
7
+ top_range,
8
+ record, true,
9
+ canvas_builder_factory: canvas_builder_factory,
10
+ iiif_range_factory: iiif_range_factory
11
+ )
12
+ end
13
+ end
14
+ class RangeBuilder < ::IIIFManifest::ManifestBuilder::RangeBuilder
15
+ def apply(manifest)
16
+ manifest << range
17
+ sub_ranges.map do |sub_range|
18
+ sub_range.apply(range['items'])
19
+ end
20
+ range_items.map do |range_item|
21
+ next if range_item.nil?
22
+ if range_item.is_a? Hash
23
+ range['items'] << range_item
24
+ else
25
+ range_item.apply(range['items'])
26
+ end
27
+ end
28
+ manifest
29
+ end
30
+
31
+ def build_range
32
+ range['id'] = path
33
+ range['label'] = ManifestBuilder.language_map(record.label) if record.try(:label).present?
34
+ range['behavior'] = 'top' if top?
35
+ range['items'] = canvas_builders.collect { |cb| { 'type' => 'Canvas', 'id' => cb.path } }
36
+ end
37
+
38
+ def canvas_builders
39
+ @canvas_builders ||= [] unless record.respond_to?(:file_set_presenters)
40
+ @canvas_builders ||= file_set_presenters.map do |file_set_presenter|
41
+ canvas_builder_factory.new(file_set_presenter, parent)
42
+ end
43
+ @canvas_builders
44
+ end
45
+
46
+ def sub_ranges
47
+ @sub_ranges ||= [] unless record.respond_to?(:ranges)
48
+ @sub_ranges ||= record.ranges.map do |sub_range|
49
+ RangeBuilder.new(
50
+ sub_range,
51
+ parent,
52
+ canvas_builder_factory: canvas_builder_factory,
53
+ iiif_range_factory: iiif_range_factory
54
+ )
55
+ end
56
+ end
57
+
58
+ def range_items
59
+ @range_items ||= [] unless record.respond_to?(:items)
60
+ @range_items ||= record.items.map do |range_item|
61
+ # Determine if this item is a range or canvas
62
+ if range_item.respond_to? :id
63
+ canvas_range_item(range_item)
64
+ elsif range_item.respond_to? :label
65
+ range_range_item(range_item)
66
+ end
67
+ end
68
+ @range_items
69
+ end
70
+
71
+ def canvas_range_item(range_item)
72
+ canvas_builder = canvas_builder_factory.new(range_item, parent)
73
+ { 'type' => 'Canvas', 'id' => canvas_builder.path }
74
+ end
75
+
76
+ def range_range_item(range_item)
77
+ RangeBuilder.new(
78
+ range_item,
79
+ parent,
80
+ canvas_builder_factory: canvas_builder_factory,
81
+ iiif_range_factory: iiif_range_factory
82
+ )
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,38 @@
1
+ module IIIFManifest
2
+ module V3
3
+ class ManifestFactory
4
+ class << self
5
+ def new(work, manifest_service_locator: ManifestServiceLocator)
6
+ super(manifest_service_locator).new(work)
7
+ end
8
+ end
9
+
10
+ delegate :collection_manifest_builder, :manifest_builder, :sammelband_manifest_builder,
11
+ to: :manifest_service_locator
12
+ attr_reader :manifest_service_locator
13
+
14
+ def initialize(manifest_service_locator)
15
+ @manifest_service_locator = manifest_service_locator
16
+ end
17
+
18
+ def new(work)
19
+ if !work.work_presenters.empty?
20
+ if sammelband?(work) || !work.file_set_presenters.empty?
21
+ manifest_builder.new(work)
22
+ elsif work.file_set_presenters.empty?
23
+ work = IIIFManifest::IIIFCollection.new(work)
24
+ collection_manifest_builder.new(work)
25
+ end
26
+ else
27
+ manifest_builder.new(work)
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def sammelband?(work)
34
+ work.respond_to?(:sammelband?) && work.sammelband?
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,148 @@
1
+ module IIIFManifest
2
+ module V3
3
+ class ManifestServiceLocator < IIIFManifest::ManifestServiceLocator
4
+ class << self
5
+ # Builders which receive a work as an argument to .new and return objects
6
+ # that respond to #apply.
7
+ def manifest_builders
8
+ composite_builder_factory.new(
9
+ record_property_builder,
10
+ structure_builder,
11
+ composite_builder: composite_builder
12
+ )
13
+ end
14
+
15
+ def collection_manifest_builders
16
+ composite_builder_factory.new(
17
+ record_property_builder,
18
+ child_manifest_builder_factory,
19
+ composite_builder: composite_builder
20
+ )
21
+ end
22
+
23
+ def iiif_collection_factory
24
+ IIIFManifest::V3::ManifestBuilder::IIIFManifest::Collection
25
+ end
26
+
27
+ def record_property_builder
28
+ IIIFManifest::ManifestServiceLocator::InjectedFactory.new(
29
+ ManifestBuilder::RecordPropertyBuilder,
30
+ iiif_search_service_factory: iiif_search_service_factory,
31
+ iiif_autocomplete_service_factory: iiif_autocomplete_service_factory,
32
+ canvas_builder_factory: deep_canvas_builder_factory
33
+ # canvas_builder_factory: canvas_builder_factory
34
+ )
35
+ end
36
+
37
+ def structure_builder
38
+ IIIFManifest::ManifestServiceLocator::InjectedFactory.new(
39
+ ManifestBuilder::StructureBuilder,
40
+ canvas_builder_factory: canvas_builder,
41
+ iiif_range_factory: iiif_range_factory
42
+ )
43
+ end
44
+
45
+ def canvas_builder_factory
46
+ IIIFManifest::ManifestBuilder::CanvasBuilderFactory.new(
47
+ composite_builder: composite_builder,
48
+ canvas_builder_factory: canvas_builder
49
+ )
50
+ end
51
+
52
+ def canvas_builder
53
+ IIIFManifest::ManifestServiceLocator::InjectedFactory.new(
54
+ ManifestBuilder::CanvasBuilder,
55
+ iiif_canvas_factory: iiif_canvas_factory,
56
+ content_builder: content_builder,
57
+ choice_builder: choice_builder,
58
+ iiif_annotation_page_factory: iiif_annotation_page_factory
59
+ )
60
+ end
61
+
62
+ def content_builder
63
+ IIIFManifest::ManifestServiceLocator::InjectedFactory.new(
64
+ ManifestBuilder::ContentBuilder,
65
+ iiif_annotation_factory: iiif_annotation_factory,
66
+ body_builder_factory: body_builder_factory
67
+ )
68
+ end
69
+
70
+ def choice_builder
71
+ IIIFManifest::ManifestServiceLocator::InjectedFactory.new(
72
+ ManifestBuilder::ChoiceBuilder,
73
+ iiif_annotation_factory: iiif_annotation_factory,
74
+ body_builder_factory: body_builder_factory,
75
+ iiif_choice_factory: iiif_choice_factory
76
+ )
77
+ end
78
+
79
+ def body_builder_factory
80
+ IIIFManifest::ManifestServiceLocator::InjectedFactory.new(
81
+ ManifestBuilder::BodyBuilder,
82
+ iiif_body_factory: iiif_body_factory,
83
+ image_service_builder_factory: image_service_builder_factory
84
+ )
85
+ end
86
+
87
+ def image_service_builder_factory
88
+ IIIFManifest::ManifestServiceLocator::InjectedFactory.new(
89
+ ManifestBuilder::ImageServiceBuilder,
90
+ iiif_service_factory: iiif_service_factory
91
+ )
92
+ end
93
+
94
+ def sequence_builder
95
+ raise NotImplementedError
96
+ end
97
+
98
+ def sammelband_sequence_builder
99
+ raise NotImplementedError
100
+ end
101
+
102
+ def sequence_factory
103
+ raise NotImplementedError
104
+ end
105
+
106
+ def iiif_service_factory
107
+ IIIFManifest::V3::ManifestBuilder::IIIFService
108
+ end
109
+
110
+ def iiif_body_factory
111
+ IIIFManifest::V3::ManifestBuilder::IIIFManifest::Body
112
+ end
113
+
114
+ def iiif_choice_factory
115
+ IIIFManifest::V3::ManifestBuilder::IIIFManifest::Choice
116
+ end
117
+
118
+ def iiif_annotation_factory
119
+ IIIFManifest::V3::ManifestBuilder::IIIFManifest::Annotation
120
+ end
121
+
122
+ def iiif_annotation_page_factory
123
+ IIIFManifest::V3::ManifestBuilder::IIIFManifest::AnnotationPage
124
+ end
125
+
126
+ def iiif_manifest_factory
127
+ IIIFManifest::V3::ManifestBuilder::IIIFManifest
128
+ end
129
+
130
+ def iiif_canvas_factory
131
+ IIIFManifest::V3::ManifestBuilder::IIIFManifest::Canvas
132
+ end
133
+
134
+ def iiif_range_factory
135
+ IIIFManifest::V3::ManifestBuilder::IIIFManifest::Range
136
+ end
137
+
138
+ def iiif_search_service_factory
139
+ IIIFManifest::V3::ManifestBuilder::IIIFManifest::SearchService
140
+ end
141
+
142
+ def iiif_autocomplete_service_factory
143
+ IIIFManifest::V3::ManifestBuilder::IIIFManifest::AutocompleteService
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
@@ -1,3 +1,3 @@
1
1
  module IIIFManifest
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iiif_manifest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-02-28 00:00:00.000000000 Z
12
+ date: 2018-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '4'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bixby
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.0'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: bundler
30
44
  requirement: !ruby/object:Gem::Requirement
@@ -151,6 +165,19 @@ files:
151
165
  - lib/iiif_manifest/manifest_builder/structure_builder.rb
152
166
  - lib/iiif_manifest/manifest_factory.rb
153
167
  - lib/iiif_manifest/manifest_service_locator.rb
168
+ - lib/iiif_manifest/v3.rb
169
+ - lib/iiif_manifest/v3/display_content.rb
170
+ - lib/iiif_manifest/v3/manifest_builder.rb
171
+ - lib/iiif_manifest/v3/manifest_builder/body_builder.rb
172
+ - lib/iiif_manifest/v3/manifest_builder/canvas_builder.rb
173
+ - lib/iiif_manifest/v3/manifest_builder/choice_builder.rb
174
+ - lib/iiif_manifest/v3/manifest_builder/content_builder.rb
175
+ - lib/iiif_manifest/v3/manifest_builder/iiif_service.rb
176
+ - lib/iiif_manifest/v3/manifest_builder/image_service_builder.rb
177
+ - lib/iiif_manifest/v3/manifest_builder/record_property_builder.rb
178
+ - lib/iiif_manifest/v3/manifest_builder/structure_builder.rb
179
+ - lib/iiif_manifest/v3/manifest_factory.rb
180
+ - lib/iiif_manifest/v3/manifest_service_locator.rb
154
181
  - lib/iiif_manifest/version.rb
155
182
  homepage: http://github.com/projecthydra-labs/iiif_manifest
156
183
  licenses: []