Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

Commit

Permalink
Adding JPG strategy from IIIF Print
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyf committed Mar 27, 2023
1 parent 5f1ca02 commit 7d235a0
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/space_stone/pdf_splitter/strategies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ module Strategies
end

require 'space_stone/pdf_splitter/strategies/base'
require 'space_stone/pdf_splitter/strategies/jpg'
4 changes: 4 additions & 0 deletions lib/space_stone/pdf_splitter/strategies/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Base
# What is the image quality we're using?
class_attribute :quality, default: nil

class_attribute :gsdevice, instance_accessor: false

##
# @param path [String] the path to the source PDF that we're processing.
# @param baseid [String] used for creating a unique identifier
Expand Down Expand Up @@ -93,6 +95,8 @@ def gsconvert
# rubocop:enable Metrics/MethodLength

def gsdevice
return self.class.gsdevice if self.class.gsdevice

raise NotImplementedError
end

Expand Down
14 changes: 14 additions & 0 deletions lib/space_stone/pdf_splitter/strategies/jpg.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module SpaceStone
module PdfSplitter
module Strategies
# The purpose of this class is to split the PDF into constituent jpg files.
class Jpg < Strategies::Base
self.image_extension = 'jpg'
self.quality = '50'
self.gsdevice = 'jpeg'
end
end
end
end
11 changes: 11 additions & 0 deletions spec/space_stone/pdf_splitter/strategies/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,15 @@

# Becasue the described class is an abstract class, we want to verify its public interface.
it { is_expected.to be_a(Enumerable) }

describe '.gsdevice' do
subject { described_class.gsdevice }
it { is_expected.to be_nil }
end

describe '#gsdevice' do
it "expects that you will have set .gsdevice in the subclass" do
expect { subject.send(:gsdevice) }.to raise_error(NotImplementedError)
end
end
end
34 changes: 34 additions & 0 deletions spec/space_stone/pdf_splitter/strategies/jpg_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe SpaceStone::PdfSplitter::Strategies::Jpg do
let(:path) { __FILE__ }
let(:pdf_pages_summary) { double(SpaceStone::PdfSplitter::PdfPagesSummary) }
let(:splitter) { described_class.new(path, pdf_pages_summary: pdf_pages_summary) }

describe '.gsdevice' do
subject { described_class.gsdevice }
it { is_expected.to eq('jpeg') }
end

describe '#gsdevice' do
subject { splitter.send(:gsdevice) }
it { is_expected.to eq('jpeg') }
end

describe '#quality' do
subject { splitter.quality }
it { is_expected.to eq(described_class.quality) }
end

describe '#quality?' do
subject { splitter.quality? }
it { is_expected.to be_truthy }
end

describe '#image_extension' do
subject { splitter.image_extension }
it { is_expected.to eq('jpg') }
end
end

0 comments on commit 7d235a0

Please sign in to comment.