Sha256: 1bf34622a8b06e0d7c6f5d7e06f0ec47ec881382c58cbd4d8d14aa9c9c35d3b9

Contents?: true

Size: 1.6 KB

Versions: 32

Compression:

Stored size: 1.6 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 [String] label
      # @param [Array] uploads
      # @param [Hash<String,Hash<String,String>>] uploads_metadata the file level metadata
      # @param [Array] files
      # @param [Class] type_strategy (FileTypeFileSetStrategy) a class that helps us determine how to type the fileset
      def initialize(label:, uploads: [], uploads_metadata: {}, files: [], type_strategy: FileTypeFileSetStrategy)
        @label = label
        @type_strategy = type_strategy
        @files = if uploads.empty?
                   files
                 else
                   uploads.map do |upload|
                     File.new(**file_args(upload, uploads_metadata.fetch(upload.filename, {})))
                   end
                 end
      end

      def as_json
        {
          type: type_strategy.run(files: files),
          label: label,
          structural: {
            contains: files.map(&:as_json)
          },
          version: 1
        }
      end

      private

      attr_reader :files, :label, :type_strategy

      # 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
        args.transform_keys(&:to_sym)
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
sdr-client-0.96.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.95.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.94.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.93.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.92.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.91.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.90.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.89.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.88.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.87.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.86.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.85.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.84.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.83.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.82.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.81.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.80.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.79.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.78.0 lib/sdr_client/deposit/file_set.rb
sdr-client-0.77.1 lib/sdr_client/deposit/file_set.rb