Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyf committed Jul 18, 2023
1 parent 4bb8491 commit f1111f1
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions lib/iiif_print/split_pdfs/derivative_rodeo_splitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DerivativeRodeoSplitter
#
# @return [Array] paths to images split from each page of PDF file
def self.call(filename, file_set:)
new(filename, file_set: file_set).split_files
new(filename, file_set: file_set).call
end

def initialize(filename, file_set:, output_tmp_dir: Dir.tmpdir)
Expand Down Expand Up @@ -60,20 +60,49 @@ def initialize(filename, file_set:, output_tmp_dir: Dir.tmpdir)
attr_reader :preprocessed_location_template

##
# @return [Array<Strings>] the paths to each of the images split off from the PDF.
# @return [Array<Strings>] the local paths to each of the images split off from the PDF.
def call
# TODO: Could we off-load the copy to another job? I'm afraid of the "cost" of copying
# a large number of files.
copy(split_files)
end

private

##
# @return [Array<DerivativeRodeo::StorageLocations::BaseLocation>]
def split_files
DerivativeRodeo::Generators::PdfSplitGenerator.new(
input_uris: [@input_uri],
output_location_template: output_location_template,
preprocessed_location_template: preprocessed_location_template
).generated_files.map(&:file_path)
).generated_files
rescue => e
message = "#{self.class}##{__method__} encountered `#{e.class}' “#{e}” for " \
"input_uri: #{@input_uri.inspect}, " \
"output_location_template: #{output_location_template.inspect}, and" \
"preprocessed_location_template: #{preprocessed_location_template.inspect}."
exception = RuntimeError.new(message)
exception.set_backtrace(e.backtrace)
DerivativeRodeo.logger.error(message)
raise exception
end

##
# @param [Array<DerivativeRodeo::StorageLocations::BaseLocation>]
# @return [Array<String>]
def copy(generated_files)
DerivativeRodeo::Generators::CopyGenerator.new(
input_uris: generated_files.map(&:file_uri),
output_location_template: output_location_template
).generated_files.map(&:file_path)
rescue => e
message = "#{self.class}##{__method__} encountered `#{e.class}' “#{e}” for " \
"input_uri: #{@input_uri.inspect}, " \
"output_location_template: #{output_location_template.inspect}"
exception = RuntimeError.new(message)
exception.set_backtrace(e.backtrace)
DerivativeRodeo.logger.error(message)
raise exception
end
end
Expand Down

0 comments on commit f1111f1

Please sign in to comment.