Class: IiifPrint::SplitPdfs::ChildWorkCreationFromPdfService
- Inherits:
-
Object
- Object
- IiifPrint::SplitPdfs::ChildWorkCreationFromPdfService
- Defined in:
- lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb
Class Method Summary collapse
-
.count_existing_pdfs(_work) ⇒ Object
TODO: implement a method to count existing PDFs on a work to support adding more PDFs to an existing work.
- .filter_file_ids(input) ⇒ Object
-
.iiif_print_split?(work:) ⇒ Boolean
Is child work splitting defined for model?.
-
.pdf_paths(files:) ⇒ Array
Load an array of paths to pdf files.
-
.pdfs?(paths:) ⇒ Boolean
Are there any PDF files?.
-
.pdfs_only_for(paths) ⇒ Object
TODO: Consider other methods to identify a PDF file.
-
.queue_job(work:, file_locations:, user:, admin_set_id:) ⇒ Object
Submit the job to split PDF into child works.
-
.upload_path(upload) ⇒ Object
Given Hyrax::Upload object, return path to file on local filesystem.
Class Method Details
.count_existing_pdfs(_work) ⇒ Object
TODO: implement a method to count existing PDFs on a work to support
adding more PDFs to an existing work.
63 64 65 |
# File 'lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb', line 63 def self.count_existing_pdfs(_work) 0 end |
.filter_file_ids(input) ⇒ Object
51 52 53 |
# File 'lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb', line 51 def self.filter_file_ids(input) Array.wrap(input).select(&:present?) end |
.iiif_print_split?(work:) ⇒ Boolean
Is child work splitting defined for model?
21 22 23 24 25 |
# File 'lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb', line 21 def self.iiif_print_split?(work:) # defined only if work has include IiifPrint.model_configuration with pdf_split_child_model return true if work.try(:iiif_print_config)&.pdf_split_child_model false end |
.pdf_paths(files:) ⇒ Array
Load an array of paths to pdf files
10 11 12 13 14 15 16 |
# File 'lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb', line 10 def self.pdf_paths(files:) upload_ids = filter_file_ids(files) return [] if upload_ids.empty? uploads = Hyrax::UploadedFile.find(upload_ids) paths = uploads.map(&method(:upload_path)) pdfs_only_for(paths) end |
.pdfs?(paths:) ⇒ Boolean
Are there any PDF files?
30 31 32 33 34 |
# File 'lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb', line 30 def self.pdfs?(paths:) pdf_paths = pdfs_only_for(paths) return false unless pdf_paths.count.positive? true end |
.pdfs_only_for(paths) ⇒ Object
TODO: Consider other methods to identify a PDF file.
This sub-selection may need to be moved to use mimetype if there
is a need to support paths not ending in .pdf (i.e. remote_urls)
70 71 72 |
# File 'lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb', line 70 def self.pdfs_only_for(paths) paths.select { |path| path.end_with?('.pdf', '.PDF') } end |
.queue_job(work:, file_locations:, user:, admin_set_id:) ⇒ Object
Submit the job to split PDF into child works
41 42 43 44 45 46 47 48 49 |
# File 'lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb', line 41 def self.queue_job(work:, file_locations:, user:, admin_set_id:) work.iiif_print_config.pdf_splitter_job.perform_later( work, file_locations, user, admin_set_id, count_existing_pdfs(work) ) end |
.upload_path(upload) ⇒ Object
Given Hyrax::Upload object, return path to file on local filesystem
56 57 58 59 |
# File 'lib/iiif_print/split_pdfs/child_work_creation_from_pdf_service.rb', line 56 def self.upload_path(upload) # so many layers to this onion: upload.file.file.file end |