Skip to content

Commit

Permalink
Improve guard clause in attach_datastreams method
Browse files Browse the repository at this point in the history
  • Loading branch information
masaball committed Apr 5, 2024
1 parent 109a3be commit 57f9796
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lib/avalon/batch/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,14 @@ def self.attach_datastreams_to_master_file( master_file, filename, captions )
master_file.structuralMetadata.original_name = structural_file
end
captions.each do |c|
return unless c.present?
if c[:caption_file].present? && FileLocator.new(c[:caption_file]).exist?
filename = c[:caption_file].split('/').last
label = c[:caption_label].presence || filename
language = c[:caption_language].present? ? caption_language(c[:caption_language]) : Settings.caption_default.language
supplemental_file = SupplementalFile.new(label: label, tags: ['caption'], language: language)
supplemental_file.file.attach(io: FileLocator.new(c[:caption_file]).reader, filename: filename)
supplemental_file.save
master_file.supplemental_files += [supplemental_file]
end
next unless c.present? && c[:caption_file].present? && FileLocator.new(c[:caption_file]).exist?
filename = c[:caption_file].split('/').last
label = c[:caption_label].presence || filename
language = c[:caption_language].present? ? caption_language(c[:caption_language]) : Settings.caption_default.language
supplemental_file = SupplementalFile.new(label: label, tags: ['caption'], language: language)
supplemental_file.file.attach(io: FileLocator.new(c[:caption_file]).reader, filename: filename)
supplemental_file.save
master_file.supplemental_files += [supplemental_file]
end
end

Expand Down

0 comments on commit 57f9796

Please sign in to comment.