Sha256: 44c8215e527848ad475a3fae55584f3ab11c712d71aaead31252e15d7e437176

Contents?: true

Size: 1.41 KB

Versions: 41

Compression:

Stored size: 1.41 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>>] 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/fileset.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

41 entries across 41 versions & 1 rubygems

Version Path
sdr-client-0.51.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.51.0.beta.1 lib/sdr_client/deposit/file_set.rb
sdr-client-0.50.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.49.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.48.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.47.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.46.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.45.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.44.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.43.1 lib/sdr_client/deposit/file_set.rb
sdr-client-0.43.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.42.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.41.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.40.1 lib/sdr_client/deposit/file_set.rb
sdr-client-0.40.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.39.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.38.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.37.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.36.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.35.1 lib/sdr_client/deposit/file_set.rb