Sha256: 673ba15cb349b4d2508efac7044ea333061dfff1ee4b0b06db7c91c07db4751e

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module SdrClient
  module Deposit
    # This represents the FileSet metadata that we send to the server for doing a deposit
    class FileSet
      def initialize(uploads: [], uploads_metadata: {}, files: [], label:)
        @label = label
        @files = if !uploads.empty?
                   uploads.map do |upload|
                     File.new(file_args(upload, uploads_metadata.fetch(upload.filename, {})))
                   end
                 else
                   files
                 end
      end

      def as_json
        {
          "type": 'http://cocina.sul.stanford.edu/models/fileset.jsonld',
          "label": label,
          structural: {
            contains: files.map(&:as_json)
          }
        }
      end

      private

      attr_reader :files, :label

      def file_args(upload, upload_metadata)
        args = {
          external_identifier: upload.signed_id,
          label: upload.filename,
          filename: upload.filename
        }
        args.merge(upload_metadata)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sdr-client-0.8.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.7.1 lib/sdr_client/deposit/file_set.rb
sdr-client-0.7.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.6.0 lib/sdr_client/deposit/file_set.rb