Sha256: 1988bf7c3ce8c2fc41c5590417ff0687f316b98e38454a732e038cb38470943d

Contents?: true

Size: 1.04 KB

Versions: 11

Compression:

Stored size: 1.04 KB

Contents

module IIIFManifest
  class ManifestBuilder
    class CanvasBuilder
      attr_reader :record, :parent, :iiif_canvas_factory, :image_builder

      def initialize(record, parent, iiif_canvas_factory:, image_builder:)
        @record = record
        @parent = parent
        @iiif_canvas_factory = iiif_canvas_factory
        @image_builder = image_builder
        apply_record_properties
        attach_image if display_image
      end

      def canvas
        @canvas ||= iiif_canvas_factory.new
      end

      def path
        "#{parent.manifest_url}/canvas/#{record.id}"
      end

      def apply(sequence)
        return sequence if canvas.images.blank?
        sequence.canvases += [canvas]
        sequence
      end

      private

      def display_image
        record.display_image if record.respond_to?(:display_image)
      end

      def apply_record_properties
        canvas['@id'] = path
        canvas.label = record.to_s
      end

      def attach_image
        image_builder.new(display_image).apply(canvas)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/iiif_manifest-1.5.0/lib/iiif_manifest/manifest_builder/canvas_builder.rb
iiif_manifest-1.6.0 lib/iiif_manifest/manifest_builder/canvas_builder.rb
iiif_manifest-1.5.0 lib/iiif_manifest/manifest_builder/canvas_builder.rb
iiif_manifest-1.4.0 lib/iiif_manifest/manifest_builder/canvas_builder.rb
iiif_manifest-1.3.1 lib/iiif_manifest/manifest_builder/canvas_builder.rb
iiif_manifest-1.3.0 lib/iiif_manifest/manifest_builder/canvas_builder.rb
iiif_manifest-1.2.0 lib/iiif_manifest/manifest_builder/canvas_builder.rb
iiif_manifest-1.1.1 lib/iiif_manifest/manifest_builder/canvas_builder.rb
iiif_manifest-1.1.0 lib/iiif_manifest/manifest_builder/canvas_builder.rb
iiif_manifest-0.4.0 lib/iiif_manifest/manifest_builder/canvas_builder.rb
iiif_manifest-0.3.0 lib/iiif_manifest/manifest_builder/canvas_builder.rb