Sha256: 1a69a0da5db18cd3d4126d2a3143260b5953ff8777f541a1bbab766eb482ea5e

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

module IIIFManifest
  class ManifestBuilder
    class ResourceBuilder
      attr_reader :display_image, :iiif_resource_factory, :image_service_builder_factory
      def initialize(display_image, iiif_resource_factory:, image_service_builder_factory:)
        @display_image = display_image
        @iiif_resource_factory = iiif_resource_factory
        @image_service_builder_factory = image_service_builder_factory
      end

      def apply(annotation)
        resource['@id'] = display_image.url
        resource['@type'] = 'dctypes:Image'
        resource['height'] = display_image.height
        resource['width'] = display_image.width
        resource['format'] = display_image.format
        image_service_builder.apply(resource) if iiif_endpoint
        annotation.resource = resource
      end

      private

        def resource
          @resource ||= iiif_resource_factory.new
        end

        def iiif_endpoint
          display_image.try(:iiif_endpoint)
        end

        def image_service_builder
          image_service_builder_factory.new(iiif_endpoint)
        end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
iiif_manifest-1.0.1 lib/iiif_manifest/manifest_builder/resource_builder.rb
iiif_manifest-1.0.0 lib/iiif_manifest/manifest_builder/resource_builder.rb
iiif_manifest-0.6.0 lib/iiif_manifest/manifest_builder/resource_builder.rb
iiif_manifest-0.5.0 lib/iiif_manifest/manifest_builder/resource_builder.rb