class IiifS3::Collection

Class Collection is an abstraction over the IIIF Collection, which is an aggregation of IIIF manifests.

@author David Newbury <david.newbury@gmail.com>

Constants

TYPE

@return [String] The IIIF Type for collections

Attributes

collections[R]
manifests[R]

Public Class Methods

new(label, config, name="top") click to toggle source
# File lib/iiif_s3/collection.rb, line 17
def initialize(label, config, name="top")  
  raise IiifS3::Error::MissingCollectionName if label.nil? || label.empty?
  @config = config
  @manifests = []
  @collections = []
  self.label = label
  self.id = "collection/#{name}"
end

Public Instance Methods

add_collection(collection) click to toggle source
# File lib/iiif_s3/collection.rb, line 26
def add_collection(collection)
  raise IiifS3::Error::NotACollection unless collection.respond_to?(:type) && collection.type == Collection::TYPE
  @collections.push(collection)
end
add_manifest(manifest) click to toggle source
# File lib/iiif_s3/collection.rb, line 31
def add_manifest(manifest)
  raise IiifS3::Error::NotAManifest unless manifest.respond_to?(:type) && manifest.type == Manifest::TYPE
  @manifests.push(manifest)
end
to_json() click to toggle source

The JSON representation of this collection in the IIIF-expected format

@return [String] The JSON representation as a string

# File lib/iiif_s3/collection.rb, line 41
def to_json
  obj = base_properties
  obj["collections"] = collect_object(collections) unless collections.empty?
  obj["manifests"] = collect_object(manifests) unless manifests.empty?
  JSON.pretty_generate obj
end

Protected Instance Methods

collect_object(things) click to toggle source
# File lib/iiif_s3/collection.rb, line 50
def collect_object(things)
  things.collect do |thing|
    {
      "@id" => thing.id,
      "@type" => thing.type,
      "label" => thing.label
    }
  end
end