class WaxIiif::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]
label[R]
manifests[R]
Public Class Methods
new(config)
click to toggle source
# File lib/wax_iiif/collection.rb, line 13 def initialize(config) raise WaxIiif::Error::MissingCollectionName if config.collection_label.to_s.empty? @config = config @manifests = [] @collections = [] @label = @config.collection_label self.id = "collection/#{@label}" end
Public Instance Methods
add_collection(collection)
click to toggle source
# File lib/wax_iiif/collection.rb, line 24 def add_collection(collection) raise WaxIiif::Error::NotACollection unless collection.respond_to?(:type) && collection.type == Collection::TYPE @collections.push(collection) end
add_manifest(manifest)
click to toggle source
# File lib/wax_iiif/collection.rb, line 29 def add_manifest(manifest) raise WaxIiif::Error::NotAManifest unless manifest.respond_to?(:type) && manifest.type == Manifest::TYPE @manifests.push(manifest) end
to_json(*_args)
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/wax_iiif/collection.rb, line 39 def to_json(*_args) 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/wax_iiif/collection.rb, line 48 def collect_object(things) things.collect do |thing| { '@id' => thing.id, '@type' => thing.type, 'label' => thing.label } end end