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)


173
174
175
# File 'app/models/hyrax/file_metadata.rb', line 173

def to_rdf_representation
  name
end

Instance Method Details

#content#to_s

Deprecated.

get content from #file instead

Returns:

  • (#to_s)


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

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



213
214
215
# File 'app/models/hyrax/file_metadata.rb', line 213

def download_id
  id
end

#extracted_file?Boolean

Returns:

  • (Boolean)


192
193
194
# File 'app/models/hyrax/file_metadata.rb', line 192

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



240
241
242
243
244
# File 'app/models/hyrax/file_metadata.rb', line 240

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)


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

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

#original_file?Boolean

Returns:

  • (Boolean)


180
181
182
# File 'app/models/hyrax/file_metadata.rb', line 180

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

#thumbnail_file?Boolean

Returns:

  • (Boolean)


186
187
188
# File 'app/models/hyrax/file_metadata.rb', line 186

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

#titleObject



209
210
211
# File 'app/models/hyrax/file_metadata.rb', line 209

def title
  label
end

#to_rdf_representationString

Returns:

  • (String)


205
206
207
# File 'app/models/hyrax/file_metadata.rb', line 205

def to_rdf_representation
  self.class.to_rdf_representation
end

#valid?Boolean

Returns:

  • (Boolean)


217
218
219
# File 'app/models/hyrax/file_metadata.rb', line 217

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