Class: Assembly::ContentMetadata::File

Inherits:
Object
  • Object
show all
Defined in:
lib/assembly-objectfile/content_metadata/file.rb

Overview

Represents a single File

Constant Summary collapse

ATTRIBUTES_FOR_TYPE =

default publish/preserve/shelve attributes used in content metadata if no mimetype specific attributes are specified for a given file, define some defaults, and override for specific mimetypes below

{
  'default' => { preserve: 'yes', shelve: 'no', publish: 'no' },
  'image/tif' => { preserve: 'yes', shelve: 'no', publish: 'no' },
  'image/tiff' => { preserve: 'yes', shelve: 'no', publish: 'no' },
  'image/jp2' => { preserve: 'no', shelve: 'yes', publish: 'yes' },
  'image/jpeg' => { preserve: 'yes', shelve: 'no', publish: 'no' },
  'audio/wav' => { preserve: 'yes', shelve: 'no', publish: 'no' },
  'audio/x-wav' => { preserve: 'yes', shelve: 'no', publish: 'no' },
  'audio/mp3' => { preserve: 'no', shelve: 'yes', publish: 'yes' },
  'audio/mpeg' => { preserve: 'no', shelve: 'yes', publish: 'yes' },
  'application/pdf' => { preserve: 'yes', shelve: 'yes', publish: 'yes' },
  'plain/text' => { preserve: 'yes', shelve: 'yes', publish: 'yes' },
  'text/plain' => { preserve: 'yes', shelve: 'yes', publish: 'yes' },
  'image/png' => { preserve: 'yes', shelve: 'yes', publish: 'no' },
  'application/zip' => { preserve: 'yes', shelve: 'no', publish: 'no' },
  'application/json' => { preserve: 'yes', shelve: 'yes', publish: 'yes' }
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(file:, bundle: nil, style: nil) ⇒ File

Returns a new instance of File.

Parameters:



32
33
34
35
36
# File 'lib/assembly-objectfile/content_metadata/file.rb', line 32

def initialize(file:, bundle: nil, style: nil)
  @bundle = bundle
  @file = file
  @style = style
end

Instance Method Details

#file_attributes(provided_file_attributes) ⇒ Object



50
51
52
# File 'lib/assembly-objectfile/content_metadata/file.rb', line 50

def file_attributes(provided_file_attributes)
  file.file_attributes || provided_file_attributes[mimetype] || provided_file_attributes['default'] || ATTRIBUTES_FOR_TYPE[mimetype] || ATTRIBUTES_FOR_TYPE['default']
end

#file_id(common_path:, flatten_folder_structure:) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/assembly-objectfile/content_metadata/file.rb', line 40

def file_id(common_path:, flatten_folder_structure:)
  # set file id attribute, first check the relative_path parameter on the object, and if it is set, just use that
  return file.relative_path if file.relative_path

  # if the relative_path attribute is not set, then use the path attribute and check to see if we need to remove the common part of the path
  file_id = common_path ? file.path.gsub(common_path, '') : file.path
  file_id = ::File.basename(file_id) if flatten_folder_structure
  file_id
end

#image_dataObject



54
55
56
# File 'lib/assembly-objectfile/content_metadata/file.rb', line 54

def image_data
  { height: file.exif.imageheight, width: file.exif.imagewidth }
end