Class: IiifS3::Manifest

Inherits:
Object
  • Object
show all
Includes:
BaseProperties
Defined in:
lib/iiif_s3/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.

Author:

Constant Summary collapse

TYPE =

Returns The IIIF default type for a manifest.

Returns:

  • (String)

    The IIIF default type for a manifest.

"sc:Manifest"

Instance Attribute Summary

Attributes included from BaseProperties

#attribution, #description, #id, #label, #license, #logo, #metadata, #related

Instance Method Summary collapse

Methods included from BaseProperties

#base_properties, #save, #type

Methods included from Utilities::Helpers

#add_default_redirect, #add_file_to_s3, #generate_build_location, #generate_id, #generate_image_location, #get_data_path, #get_s3_key, #save_to_disk

Constructor Details

#initialize(image_records, config, opts = {}) ⇒ Manifest

This will initialize a new manifest.

Parameters:

  • image_records (Array<ImageRecord>)

    An array of ImageRecord types

  • config (<type>)

    <description>

  • opts (<type>) (defaults to: {})

    <description>

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/iiif_s3/manifest.rb', line 31

def initialize(image_records,config, opts = {})
  @config = config
  image_records.each do |record|
    raise IiifS3::Error::InvalidImageData, "The data provided to the manifest were not ImageRecords" unless record.is_a? ImageRecord
  end

  @primary = image_records.find{|obj| obj.is_primary}
  raise IiifS3::Error::InvalidImageData, "No 'is_primary' was found in the image data." unless @primary
  raise IiifS3::Error::MultiplePrimaryImages, "Multiple primary images were found in the image data." unless image_records.count{|obj| obj.is_primary} == 1

  self.id =          "#{@primary.id}/manifest"
  self.label =        @primary.label       || opts[:label]                 || ""
  self.description =  @primary.description || opts[:description]
  self.attribution =  @primary.attribution || opts.fetch(:attribution, nil) 
  self. =         @primary.        || opts.fetch(:logo, nil)
  self.license =      @primary.license     || opts.fetch(:license, nil)
  self. =     @primary.    || opts.fetch(:metadata, nil)

  @sequences = build_sequence(image_records)
end

Instance Method Details

#save_all_files_to_diskVoid

Save the manifest and all sub-resources to disk, using the paths contained withing the IiifS3::Config object passed at initialization.

Will create the manifest, sequences, canvases, and annotation subobjects.

Returns:

  • (Void)


75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/iiif_s3/manifest.rb', line 75

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
  return nil
end

#to_jsonString

Returns the JSON-LD representation of the manifest as a string.

Returns:

  • (String)

    the JSON-LD representation of the manifest as a string.



55
56
57
58
59
60
61
62
63
64
# File 'lib/iiif_s3/manifest.rb', line 55

def to_json
  obj = base_properties

  obj["thumbnail"]   = @primary.variants["thumbnail"].uri
  obj["viewingDirection"] = @primary.viewing_direction 
  obj["viewingHint"] = @primary.is_document ? "paged" : "individuals"
  obj["sequences"] = [@sequences]

  return JSON.pretty_generate obj
end