Class: PDFDetach
- Inherits:
-
Object
- Object
- PDFDetach
- Defined in:
- lib/pdfdetach/main.rb,
lib/pdfdetach/version.rb,
lib/pdfdetach/configuration.rb
Overview
:nodoc:
Defined Under Namespace
Classes: Configuration
Constant Summary collapse
- VERSION =
'0.20.3'
- LIB_TARGET =
'20.04'
Class Method Summary collapse
- .configuration ⇒ Object
-
.configure {|configuration| ... } ⇒ Object
On a initializer or somewhere else in your code, if you want to use a different version or binary instead of the binary provided in this gem, you can assign a path for a binary like this:.
Instance Method Summary collapse
- #get_opts(options) ⇒ Object
-
#initialize(filepath) ⇒ PDFDetach
constructor
A new instance of PDFDetach.
-
#list ⇒ Array
List all files attached.
-
#saveall(options = {}) ⇒ Object
Save all attached files in the pdf.
Constructor Details
#initialize(filepath) ⇒ PDFDetach
Returns a new instance of PDFDetach.
9 10 11 12 13 |
# File 'lib/pdfdetach/main.rb', line 9 def initialize(filepath) @src = filepath @base_path = Pathname.new("#{__dir__}/../../bin/#{LIB_TARGET}").cleanpath @binary_path = PDFDetach.configuration.binary_path end |
Class Method Details
.configuration ⇒ Object
24 25 26 |
# File 'lib/pdfdetach/configuration.rb', line 24 def self.configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
On a initializer or somewhere else in your code, if you want to use a different version or binary instead of the binary provided in this gem, you can assign a path for a binary like this:
PDFDetach.configure do |config|
config.binary_path = 'path/to/pdfdetach'
end
20 21 22 |
# File 'lib/pdfdetach/configuration.rb', line 20 def self.configure yield configuration end |
Instance Method Details
#get_opts(options) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/pdfdetach/main.rb', line 16 def get_opts() args = String.new args << " -o #{[:output]} " if [:output] args << " -enc #{[:encoding]} " if [:encoding] args << " -opw #{[:owner_password]} " if [:owner_password] args << " -upw #{[:user_password]} " if [:user_password] args end |
#list ⇒ Array
List all files attached
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pdfdetach/main.rb', line 29 def list result = run("-list #{@src}") list ||= if result[:ok] result[:out].split("\n").map do |line| next line.match(/^(\d+): (.+?)$/) { |m| m[2] } if line =~ /^(\d+):/ end else [] end list.compact end |
#saveall(options = {}) ⇒ Object
Save all attached files in the pdf
46 47 48 |
# File 'lib/pdfdetach/main.rb', line 46 def saveall( = {}) run("-saveall #{get_opts()} #{@src}")[:ok] end |