Class: SdrClient::RedesignedClient::File

Inherits:
Object
  • Object
show all
Defined in:
lib/sdr_client/redesigned_client/file.rb

Overview

This represents the File metadata that we send to the server for doing a deposit

Instance Method Summary collapse

Constructor Details

#initialize(external_identifier:, label:, filename:, **options) ⇒ File

Returns a new instance of File.

Parameters:

  • external_identifier (String)

    used for object IDs (e.g., druids)

  • label (String)

    the required object label

  • filename (String)

    a filename

  • options (Hash)

    optional parameters

Options Hash (**options):

  • view (String)

    the access level for viewing the object

  • download (String)

    the access level for downloading the object

  • location (String)

    the location for location-based access

  • preserve (Boolean)

    whether to preserve the file or not

  • shelve (Boolean)

    whether to shelve the file or not

  • publish (Boolean)

    whether to publish the file or not

  • mime_type (String)

    the MIME type of the file

  • md5 (String)

    the MD5 digest of the file

  • sha1 (String)

    the SHA1 digest of the file

  • use (String)

    the use and reproduction statement



21
22
23
24
25
26
# File 'lib/sdr_client/redesigned_client/file.rb', line 21

def initialize(external_identifier:, label:, filename:, **options)
  @external_identifier = external_identifier
  @label = label
  @filename = filename
  @options = options
end

Instance Method Details

#to_hObject

rubocop:disable Metrics/MethodLength, Metrics/AbcSize



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/sdr_client/redesigned_client/file.rb', line 28

def to_h # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  {
    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
    json[:access]['location'] if location
  end
end