Class: WaxIiif::Manifest
- Inherits:
-
Object
- Object
- WaxIiif::Manifest
- Includes:
- BaseProperties
- Defined in:
- lib/wax_iiif/manifest.rb
Overview
Class Manifest is an abstraction over the IIIF Manifest, and by extension over the entire Presentation API. It takes the internal representation of data and converts it into a collection of JSON-LD documents. Optionally, it also provides the ability to save these files to disk and upload them to Amazon S3.
Constant Summary collapse
- TYPE =
Returns The IIIF default type for a manifest.
'sc:Manifest'.freeze
Instance Attribute Summary
Attributes included from BaseProperties
#attribution, #description, #id, #label, #license, #logo, #metadata, #related
Instance Method Summary collapse
- #base_id ⇒ String
-
#initialize(image_records, config, opts = {}) ⇒ Manifest
constructor
This will initialize a new manifest.
-
#save_all_files_to_disk ⇒ Void
Save the manifest and all sub-resources to disk, using the paths contained withing the WaxIiif::Config object passed at initialization.
-
#to_json(*_args) ⇒ String
The JSON-LD representation of the manifest as a string.
Methods included from BaseProperties
#base_properties, #save, #type
Methods included from Utilities::Helpers
#escape_yaml, #generate_build_location, #generate_id, #generate_image_location, #get_data_path, #save_to_disk
Constructor Details
#initialize(image_records, config, opts = {}) ⇒ Manifest
This will initialize a new manifest.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/wax_iiif/manifest.rb', line 26 def initialize(image_records, config, opts = {}) @config = config image_records.each do |record| raise WaxIiif::Error::InvalidImageData, 'The data provided to the manifest were not ImageRecords' unless record.is_a? ImageRecord end @primary = image_records.find(&:primary?) raise WaxIiif::Error::InvalidImageData, "No 'primary?' was found in the image data." unless @primary raise WaxIiif::Error::MultiplePrimaryImages, 'Multiple primary images were found in the image data.' unless image_records.count(&:primary?) == 1 @id = generate_id "#{base_id}/manifest" @label = @primary.label || opts[:label] || '' @description = @primary.description || opts[:description] @attribution = @primary.attribution || opts.fetch(:attribution, nil) @logo = @primary.logo || opts.fetch(:logo, nil) @license = @primary.license || opts.fetch(:license, nil) @metadata = @primary. || opts.fetch(:metadata, nil) @sequences = build_sequence(image_records) end |
Instance Method Details
#base_id ⇒ String
65 66 67 |
# File 'lib/wax_iiif/manifest.rb', line 65 def base_id @primary.manifest_id || @primary.id end |
#save_all_files_to_disk ⇒ Void
Save the manifest and all sub-resources to disk, using the paths contained withing the WaxIiif::Config object passed at initialization.
Will create the manifest, sequences, canvases, and annotation subobjects.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/wax_iiif/manifest.rb', line 78 def save_all_files_to_disk data = JSON.parse(self.to_json) save_to_disk(data) data['sequences'].each do |sequence| save_to_disk(sequence) sequence['canvases'].each do |canvas| save_to_disk(canvas) canvas['images'].each do |annotation| save_to_disk(annotation) end end end nil end |
#to_json(*_args) ⇒ String
Returns the JSON-LD representation of the manifest as a string.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/wax_iiif/manifest.rb', line 51 def to_json(*_args) obj = base_properties obj['thumbnail'] = @primary.variants['thumbnail'].uri obj['viewingDirection'] = @primary.viewing_direction obj['viewingHint'] = @primary.document? ? 'paged' : 'individuals' obj['sequences'] = [@sequences] @primary.variants.each { |k, v| obj[k] = v.uri } JSON.pretty_generate obj end |