Sha256: 264418fd16247573c81c0bb9bff7c2be44dff351c7a45de270e2bb62ffb0e1e8

Contents?: true

Size: 1.43 KB

Versions: 8

Compression:

Stored size: 1.43 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
      # @param [Array] uploads
      # @param [Hash<String,Hash<String,String>>] uploads_metadata the file level metadata
      # @param [Array] files
      # @param [String] label
      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/resources/file.jsonld',
          "label": label,
          structural: {
            contains: files.map(&:as_json)
          },
          version: 1
        }
      end

      private

      attr_reader :files, :label

      # This creates the metadata for each file and symbolizes the keys
      # @return [Hash<Symbol,String>]
      def file_args(upload, upload_metadata)
        args = {
          external_identifier: upload.signed_id,
          label: upload.filename,
          filename: upload.filename
        }
        args.merge!(upload_metadata)
        # Symbolize
        Hash[args.map { |k, v| [k.to_sym, v] }]
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sdr-client-0.63.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.62.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.61.1 lib/sdr_client/deposit/file_set.rb
sdr-client-0.61.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.60.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.59.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.58.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.57.0 lib/sdr_client/deposit/file_set.rb