Sha256: b794b1eaa68b05183a46fe66c77bd437743b62d01d2b1fa0521a80e698bd6704

Contents?: true

Size: 1.88 KB

Versions: 51

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true

module SdrClient
  module Deposit
    # This represents the File metadata that we send to the server for doing a deposit
    class File
      # rubocop:disable Metrics/ParameterLists
      def initialize(external_identifier:, label:, filename:,
                     view: 'dark', download: 'none', preserve: true, shelve: true,
                     publish: true, mime_type: nil, md5: nil, sha1: nil,
                     use: nil)
        @external_identifier = external_identifier
        @label = label
        @filename = filename
        @view = view
        @download = download
        @preserve = preserve
        @shelve = view == 'dark' ? false : shelve
        @publish = publish
        @mime_type = mime_type
        @md5 = md5
        @sha1 = sha1
        @use = use
      end
      # rubocop:enable Metrics/ParameterLists

      def as_json
        {
          type: Cocina::Models::ObjectType.file,
          label: @label,
          filename: @filename,
          externalIdentifier: @external_identifier,
          access: {
            view: @view,
            download: @download
          },
          administrative: {
            sdrPreserve: @preserve,
            shelve: @shelve,
            publish: @publish
          },
          version: 1,
          hasMessageDigests: message_digests
        }.tap do |json|
          json['hasMimeType'] = @mime_type if @mime_type
          json['use'] = @use if @use
        end
      end

      private

      def message_digests
        @message_digests ||= [].tap do |message_digests|
          message_digests << create_message_digest('md5', @md5) unless @md5.nil?
          message_digests << create_message_digest('sha1', @sha1) unless @sha1.nil?
        end
      end

      def create_message_digest(algorithm, digest)
        {
          type: algorithm,
          digest: digest
        }
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
sdr-client-2.13.2 lib/sdr_client/deposit/file.rb
sdr-client-2.13.1 lib/sdr_client/deposit/file.rb
sdr-client-2.13.0 lib/sdr_client/deposit/file.rb
sdr-client-2.13.0.beta2 lib/sdr_client/deposit/file.rb
sdr-client-2.13.0.beta1 lib/sdr_client/deposit/file.rb
sdr-client-2.12.0 lib/sdr_client/deposit/file.rb
sdr-client-2.11.1 lib/sdr_client/deposit/file.rb
sdr-client-2.11.0 lib/sdr_client/deposit/file.rb
sdr-client-2.10.1 lib/sdr_client/deposit/file.rb
sdr-client-2.10.0 lib/sdr_client/deposit/file.rb
sdr-client-2.9.0 lib/sdr_client/deposit/file.rb
sdr-client-2.8.0 lib/sdr_client/deposit/file.rb
sdr-client-2.7.1 lib/sdr_client/deposit/file.rb
sdr-client-2.7.0 lib/sdr_client/deposit/file.rb
sdr-client-2.6.0 lib/sdr_client/deposit/file.rb
sdr-client-2.5.0 lib/sdr_client/deposit/file.rb
sdr-client-2.4.0 lib/sdr_client/deposit/file.rb
sdr-client-2.3.1 lib/sdr_client/deposit/file.rb
sdr-client-2.3.0 lib/sdr_client/deposit/file.rb
sdr-client-2.2.0 lib/sdr_client/deposit/file.rb