Class: Hyrax::FileMetadata

Inherits:
Valkyrie::Resource
  • Object
show all
Includes:
Hydra::Works::MimeTypes
Defined in:
app/models/hyrax/file_metadata.rb

Defined Under Namespace

Modules: Use

Constant Summary collapse

GENERIC_MIME_TYPE =
'application/octet-stream'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.to_rdf_representationString

Returns:

  • (String)


158
159
160
# File 'app/models/hyrax/file_metadata.rb', line 158

def to_rdf_representation
  name
end

Instance Method Details

#content#to_s

Deprecated.

get content from #file instead

Returns:

  • (#to_s)


210
211
212
213
214
215
216
# File 'app/models/hyrax/file_metadata.rb', line 210

def content
  Deprecation.warn('This convienince method has been deprecated. ' \
                   'Retrieve the file from the storage adapter instead.')
  file.read
rescue Valkyrie::StorageAdapter::FileNotFound
  ''
end

#download_idObject



198
199
200
# File 'app/models/hyrax/file_metadata.rb', line 198

def download_id
  id
end

#extracted_file?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'app/models/hyrax/file_metadata.rb', line 177

def extracted_file?
  pcdm_use.include?(Use::EXTRACTED_TEXT)
end

#fileValkyrie::StorageAdapter::File

Returns:

  • (Valkyrie::StorageAdapter::File)

Raises:

  • (Valkyrie::StorageAdapter::AdapterNotFoundError)

    if no adapter could be found matching the file_identifier’s scheme

  • (Valkyrie::StorageAdapter::FileNotFound)

    when the file can’t be found in the registered adapter



225
226
227
228
229
# File 'app/models/hyrax/file_metadata.rb', line 225

def file
  Valkyrie::StorageAdapter
    .adapter_for(id: file_identifier)
    .find_by(id: file_identifier)
end

#filtered_pcdm_useArray

Filters out uses not recognized by Hyrax (e.g. fedora.info/definitions/v4/repository#Binary)

Returns:

  • (Array)


184
185
186
# File 'app/models/hyrax/file_metadata.rb', line 184

def filtered_pcdm_use
  pcdm_use.select { |use| Use.use_list.include?(use) }
end

#original_file?Boolean

Returns:

  • (Boolean)


165
166
167
# File 'app/models/hyrax/file_metadata.rb', line 165

def original_file?
  pcdm_use.include?(Use::ORIGINAL_FILE)
end

#thumbnail_file?Boolean

Returns:

  • (Boolean)


171
172
173
# File 'app/models/hyrax/file_metadata.rb', line 171

def thumbnail_file?
  pcdm_use.include?(Use::THUMBNAIL_IMAGE)
end

#titleObject



194
195
196
# File 'app/models/hyrax/file_metadata.rb', line 194

def title
  label
end

#to_rdf_representationString

Returns:

  • (String)


190
191
192
# File 'app/models/hyrax/file_metadata.rb', line 190

def to_rdf_representation
  self.class.to_rdf_representation
end

#valid?Boolean

Returns:

  • (Boolean)


202
203
204
# File 'app/models/hyrax/file_metadata.rb', line 202

def valid?
  file.valid?(size: recorded_size.first, digests: { sha256: checksum&.first&.sha256 })
end