Class: Libis::Tools::MetsFile::File

Inherits:
Object
  • Object
show all
Includes:
IdContainer
Defined in:
lib/libis/tools/mets_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from IdContainer

#id, #set_from_hash, #to_s

Instance Attribute Details

#applicationsObject

Returns the value of attribute applications.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def applications
  @applications
end

#checksum_MD5Object

Returns the value of attribute checksum_MD5.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def checksum_MD5
  @checksum_MD5
end

#checksum_SHA1Object

Returns the value of attribute checksum_SHA1.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def checksum_SHA1
  @checksum_SHA1
end

#checksum_SHA256Object

Returns the value of attribute checksum_SHA256.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def checksum_SHA256
  @checksum_SHA256
end

#checksum_SHA384Object

Returns the value of attribute checksum_SHA384.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def checksum_SHA384
  @checksum_SHA384
end

#checksum_SHA512Object

Returns the value of attribute checksum_SHA512.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def checksum_SHA512
  @checksum_SHA512
end

#composition_levelObject

Returns the value of attribute composition_level.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def composition_level
  @composition_level
end

#creation_dateObject

Returns the value of attribute creation_date.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def creation_date
  @creation_date
end

#dc_recordObject

Returns the value of attribute dc_record.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def dc_record
  @dc_record
end

#entity_typeObject

Returns the value of attribute entity_type.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def entity_type
  @entity_type
end

#env_dependenciesObject

Returns the value of attribute env_dependencies.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def env_dependencies
  @env_dependencies
end

#environmentsObject

Returns the value of attribute environments.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def environments
  @environments
end

#fixity_typeObject

Returns the value of attribute fixity_type.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def fixity_type
  @fixity_type
end

#fixity_valueObject

Returns the value of attribute fixity_value.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def fixity_value
  @fixity_value
end

#group_idObject

Returns the value of attribute group_id.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def group_id
  @group_id
end

#hardware_idsObject

Returns the value of attribute hardware_ids.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def hardware_ids
  @hardware_ids
end

#hardware_infosObject

Returns the value of attribute hardware_infos.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def hardware_infos
  @hardware_infos
end

#inhibitorsObject

Returns the value of attribute inhibitors.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def inhibitors
  @inhibitors
end

#labelObject

Returns the value of attribute label.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def label
  @label
end

#locationObject

Returns the value of attribute location.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def location
  @location
end

#mimetypeObject

Returns the value of attribute mimetype.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def mimetype
  @mimetype
end

#modification_dateObject

Returns the value of attribute modification_date.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def modification_date
  @modification_date
end

#noteObject

Returns the value of attribute note.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def note
  @note
end

#preservation_levelsObject

Returns the value of attribute preservation_levels.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def preservation_levels
  @preservation_levels
end

#puidObject

Returns the value of attribute puid.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def puid
  @puid
end

#relationship_infosObject

Returns the value of attribute relationship_infos.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def relationship_infos
  @relationship_infos
end

#representationObject

Returns the value of attribute representation.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def representation
  @representation
end

#signaturesObject

Returns the value of attribute signatures.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def signatures
  @signatures
end

#sizeObject

Returns the value of attribute size.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def size
  @size
end

#software_idsObject

Returns the value of attribute software_ids.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def software_ids
  @software_ids
end

#software_infosObject

Returns the value of attribute software_infos.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def software_infos
  @software_infos
end

#source_metadataObject

Returns the value of attribute source_metadata.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def 
  @source_metadata
end

#target_locationObject

Returns the value of attribute target_location.



222
223
224
# File 'lib/libis/tools/mets_file.rb', line 222

def target_location
  @target_location
end

Instance Method Details

#add_manifestation(file) ⇒ Object



250
251
252
253
# File 'lib/libis/tools/mets_file.rb', line 250

def add_manifestation(file)
  manifestations << file
  file.master = self
end

#amdObject



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'lib/libis/tools/mets_file.rb', line 270

def amd
  dnx = {}
  tech_data = []
  # General File charateristics
  data = {
      label: label,
      note: note,
      fileCreationDate: creation_date,
      fileModificationDate: modification_date,
      FileEntityType: entity_type,
      compositionLevel: composition_level,
      # fileLocationType: 'FILE',
      # fileLocation: '',
      fileOriginalName: orig_name,
      fileOriginalPath: orig_path,
      fileOriginalID: location,
      fileExtension: ::File.extname(orig_name),
      fileMIMEType: mimetype,
      fileSizeBytes: size,
      formatLibraryId: puid
  }.cleanup
  tech_data << TechGeneralFile.new(data) unless data.empty?
  # Fixity
  %w'MD5 SHA1 SHA256 SHA384 SHA512'.each do |checksum_type|
    if (checksum = self.send("checksum_#{checksum_type}"))
      data = {
          fixityType: checksum_type,
          fixityValue: checksum,
      }.cleanup
      tech_data << TechFixity.new(data) unless data.empty?
    end
  end
  # Object characteristics
  data = {
      groupID: make_group_id
  }.cleanup
  tech_data << TechObjectChars.new(data) unless data.empty?
  # Preservation level
  if preservation_levels
    data_list = []
    preservation_levels.each do |preservation_level|
      data = {
          preservationLevelValue: preservation_level[:value],
          preservationLevelRole: preservation_level[:role],
          preservationLevelRationale: preservation_level[:rationale],
          preservationLevelDateAssigned: preservation_level[:date],
      }.cleanup
      data_list << OpenStruct.new(data) unless data.empty?
    end
    tech_data << PreservationLevel.new(array: data_list) unless data_list.empty?
  end
  # Inhibitor
  if inhibitors
    data_list = []
    inhibitors.each do |inhibitor|
      data = {
          inhibitorType: inhibitor[:type],
          inhibitorTarget: inhibitor[:target],
          inhibitorKey: inhibitor[:key],
      }.cleanup
      data_list << OpenStruct.new(data) unless data.empty?
    end
    tech_data << Inhibitor.new(array: data_list) unless data_list.empty?
  end
  # Dependencies
  if env_dependencies
    data_list = []
    env_dependencies.each do |dependency|
      data = {
          dependencyName: dependency[:name],
          dependencyIdentifierType1: dependency[:type1],
          dependencyIdentifierValue1: dependency[:value1],
          dependencyIdentifierType2: dependency[:type2],
          dependencyIdentifierValue2: dependency[:value2],
          dependencyIdentifierType3: dependency[:type3],
          dependencyIdentifierValue3: dependency[:value3],
      }.cleanup
      data_list << OpenStruct.new(data) unless data.empty?
    end
    tech_data << EnvDeps.new(array: data_list) unless data_list.empty?
  end
  # Hardware registry id
  if hardware_ids
    data_list = []
    hardware_ids.each do |id|
      data = {
          registryId: id
      }.cleanup
      data_list << OpenStruct.new(data) unless data.empty?
    end
    tech_data << HardwareId.new(array: data_list) unless data_list.empty?
  end
  # Software registry id
  if software_ids
    data_list = []
    software_ids.each do |id|
      data = {
          registryId: id
      }.cleanup
      data_list << OpenStruct.new(data) unless data.empty?
    end
    tech_data << SoftwareId.new(array: data_list) unless data_list.empty?
  end
  # Singatures
  if signatures
    data_list = []
    signatures.each do |signature|
      data = {
          signatureInformationEncoding: signature[:encoding],
          signer: signature[:signer],
          signatureMethod: signature[:method],
          signatureValue: signature[:value],
          signatureValidationRules: signature[:rules],
          signatureProperties: signature[:properties],
      }.cleanup
      data_list << OpenStruct.new(data) unless data.empty?
    end
    tech_data << Signature.new(array: data_list) unless data_list.empty?
  end
  # Hardware
  if hardware_infos
    data_list = []
    hardware_infos.each do |hardware|
      data = {
          hardwareName: hardware[:name],
          hardwareType: hardware[:type],
          hardwareOtherInformation: hardware[:info],
      }.cleanup
      data_list << OpenStruct.new(data) unless data.empty?
    end
    tech_data << HardwareInfo.new(array: data_list) unless data_list.empty?
  end
  # Software
  if software_infos
    data_list = []
    software_infos.each do |software|
      data = {
          softwareName: software[:name],
          softwareVersion: software[:version],
          softwareType: software[:type],
          softwareOtherInformation: software[:info],
          softwareDependancy: software[:dependency],
      }.cleanup
      data_list << OpenStruct.new(data) unless data.empty?
    end
    tech_data << SoftwareInfo.new(array: data_list) unless data_list.empty?
  end
  # Relationship
  if relationship_infos
    data_list = []
    relationship_infos.each do |relationship|
      data = {
          relationshipType: relationship[:type],
          relationshipSubType: relationship[:subtype],
          relatedObjectIdentifierType1: relationship[:type1],
          relatedObjectIdentifierValue1: relationship[:id1],
          relatedObjectSequence1: relationship[:seq1],
          relatedObjectIdentifierType2: relationship[:type2],
          relatedObjectIdentifierValue2: relationship[:id2],
          relatedObjectSequence2: relationship[:seq2],
          relatedObjectIdentifierType3: relationship[:type3],
          relatedObjectIdentifierValue3: relationship[:id3],
          relatedObjectSequence3: relationship[:seq3],
      }.cleanup
      data_list << OpenStruct.new(data) unless data.empty?
    end
    tech_data << RelationShip.new(array: data_list) unless data_list.empty?
  end
  # Environment
  if environments
    data_list = []
    environments.each do |environment|
      data = {
          environmentCharacteristic: environment[:characteristic],
          environmentPurpose: environment[:purpose],
          environmentNote: environment[:note],
      }.cleanup
      data_list << OpenStruct.new(data) unless data.empty?
    end
    tech_data << Environment.new(array: data_list) unless data_list.empty?
  end
  # Application
  if applications
    data_list = []
    applications.each do |application|
      data = {
          creatingApplicationName: application[:name],
          creatingApplicationVersion: application[:version],
          dateCreatedByApplication: application[:date],
      }.cleanup
      data_list << OpenStruct.new(data) unless data.empty?
    end
    tech_data << Application.new(array: data_list) unless data_list.empty?
  end
  # Finally assemble technical section
  dnx[:tech] = tech_data unless tech_data.empty?
  dnx
end

#make_group_idObject



234
235
236
# File 'lib/libis/tools/mets_file.rb', line 234

def make_group_id
  "grp#{group_id || master.id rescue id}"
end

#manifestationsObject



246
247
248
# File 'lib/libis/tools/mets_file.rb', line 246

def manifestations
  @manifestations ||= Array.new
end

#masterObject



238
239
240
# File 'lib/libis/tools/mets_file.rb', line 238

def master
  @master ||= nil
end

#master=(file) ⇒ Object



242
243
244
# File 'lib/libis/tools/mets_file.rb', line 242

def master=(file)
  @master = file
end

#orig_nameObject



255
256
257
# File 'lib/libis/tools/mets_file.rb', line 255

def orig_name
  ::File.basename(location)
end

#orig_pathObject



259
260
261
# File 'lib/libis/tools/mets_file.rb', line 259

def orig_path
  ::File.dirname(location)
end

#targetObject



263
264
265
266
267
268
# File 'lib/libis/tools/mets_file.rb', line 263

def target
  if target_location.nil?
    return "#{xml_id}#{::File.extname(location)}"
  end
  target_location
end

#xml_idObject



230
231
232
# File 'lib/libis/tools/mets_file.rb', line 230

def xml_id
  "fid#{id}"
end