Class: SdrClient::Deposit::File

Inherits:
Object
  • Object
show all
Defined in:
lib/sdr_client/deposit/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:, access: 'dark', download: 'none', preserve: true, shelve: true, publish: true, mime_type: nil, md5: nil, sha1: nil, use: nil) ⇒ File

rubocop:disable Metrics/ParameterLists



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sdr_client/deposit/file.rb', line 8

def initialize(external_identifier:, label:, filename:,
               access: '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
  @access = access
  @download = download
  @preserve = preserve
  @shelve = access == 'dark' ? false : shelve
  @publish = publish
  @mime_type = mime_type
  @md5 = md5
  @sha1 = sha1
  @use = use
end

Instance Method Details

#as_jsonObject

rubocop:enable Metrics/ParameterLists



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

def as_json
  {
    "type": 'http://cocina.sul.stanford.edu/models/file.jsonld',
    label: @label,
    filename: @filename,
    externalIdentifier: @external_identifier,
    access: {
      access: @access,
      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