Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CharacterizationService: teach #file_name about Valkyrie objects #383

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/hydra/works/services/characterization_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ def extract_metadata(content)
# Determine the filename to send to Hydra::FileCharacterization. If no source is present,
# use the name of the file from the object; otherwise, use the supplied source.
def file_name
if source
source.is_a?(File) ? File.basename(source.path) : File.basename(source)
else
object.original_name.nil? ? "original_file" : object.original_name
case object
when Hydra::PCDM::File
if source
source.is_a?(File) ? File.basename(source.path) : File.basename(source)
else
object.original_name.nil? ? "original_file" : object.original_name
end
when Hyrax::FileMetadata
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the short term, would it be helpful to (also?) add an alias #original_name to Hyrax::FileMetadata?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could; i guess in that case maybe we'd want to flip the branch order and check for object#original_name first, then fall back on source

the problem is that the object we provide as source errors on both branches of source.is_a?(File) ? File.basename(source.path) : File.basename(source) so that codepath is only appropriate when it's Hydra::PCDM::File

(i guess a further question is why it's preferred over the #original_name in the first place?)

object.original_filename
end
end

Expand Down