-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new PDF splitter option that wraps the DerivateRodeo's PdfSplitGenerator. ref #220
- Loading branch information
Showing
4 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module IiifPrint | ||
module SplitPdfs | ||
class DerivativeRodeoSplitter | ||
## | ||
# This class wraps the DerivativeRodeo::Generators::PdfSplitGenerator to find preprocessed | ||
# images, or split a PDF if there are no preprocessed images. | ||
# | ||
# TODO: override output extension from default "tiff" in Derivative Rodeo | ||
# TODO: define output_location_template & preprocessed_location_template | ||
|
||
## | ||
# @param _path [String] unused here, kept for consistant splitter method signature | ||
# @param file_set [FileSet] file set containing a PDF file to split | ||
# @return [Array] paths to images split from each page of PDF file | ||
def self.call(_path, file_set:) | ||
new(file_set: file_set).split_files | ||
end | ||
|
||
def initialize(file_set:) | ||
@path = IiifPrint::DerivativeRodeoService.derivative_rodeo_input_uri(file_set: file_set) | ||
end | ||
|
||
def split_files | ||
DerivativeRodeo::Generators::PdfSplitGenerator.new( | ||
input_uris: @path, | ||
output_location_template: template, | ||
preprocessed_location_template: location | ||
).generated_files | ||
end | ||
|
||
private | ||
|
||
def template | ||
'who knows' | ||
end | ||
|
||
def location | ||
'who knows' | ||
end | ||
end | ||
end | ||
end |
33 changes: 33 additions & 0 deletions
33
spec/iiif_print/split_pdfs/derivative_rodeo_splitter_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe IiifPrint::SplitPdfs::DerivativeRodeoSplitter do | ||
let(:path) { nil } | ||
let(:work) { double(MyWork, aark_id: '12345') } | ||
let(:file_set) { FileSet.new.tap { |fs| fs.save!(validate: false) } } | ||
|
||
describe 'class' do | ||
subject { described_class } | ||
|
||
it { is_expected.to respond_to(:call) } | ||
end | ||
|
||
describe "instance" do | ||
subject { described_class.new(file_set: file_set) } | ||
|
||
before do | ||
allow(file_set).to receive(:parent).and_return(work) | ||
# TODO: This is a hack that leverages the internals of Hydra::Works; not excited about it but | ||
# this part is only one piece of the over all integration. | ||
allow(file_set).to receive(:original_file).and_return(double(original_filename: __FILE__)) | ||
end | ||
|
||
it { is_expected.to respond_to :split_files } | ||
|
||
it 'uses the rodeo to split' do | ||
expect(DerivativeRodeo::Generators::PdfSplitGenerator).to receive(:new) | ||
described_class.call(path, file_set: file_set) | ||
end | ||
end | ||
end |