pdftk 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/pdftk.rb +22 -0
  2. metadata +3 -3
data/lib/pdftk.rb CHANGED
@@ -1,9 +1,22 @@
1
+ require 'logger'
2
+ require 'digest/md5'
3
+ require 'rbconfig'
4
+ require RbConfig::CONFIG['target_os'] == 'mingw32' && !(RUBY_VERSION =~ /1.9/) ? 'win32/open3' : 'open3'
5
+ require 'active_support/core_ext/class/attribute_accessors'
6
+
7
+ begin
8
+ require 'active_support/core_ext/object/blank'
9
+ rescue LoadError
10
+ require 'active_support/core_ext/blank'
11
+ end
12
+
1
13
  class Pdftk
2
14
  EXE_NAME = "pdftk"
3
15
  @@config = {}
4
16
  cattr_accessor :config
5
17
 
6
18
  def initialize(source_array, destination_path)
19
+ @exe_path = find_binary_path
7
20
  @source_files = source_array
8
21
  @merged_file_path = destination_path
9
22
  raise "Location of #{EXE_PATH} unknow" if @exe_path.empty?
@@ -22,4 +35,13 @@ class Pdftk
22
35
  rescue Exception => e
23
36
  raise "Failed to execute:\n#{command}\nError: #{e}"
24
37
  end
38
+
39
+ private
40
+
41
+ def find_binary_path
42
+ possible_locations = (ENV['PATH'].split(':')+%w[/usr/bin /usr/local/bin ~/bin]).uniq
43
+ exe_path ||= Pdftk.config[:exe_path] unless Pdftk.config.empty?
44
+ exe_path ||= possible_locations.map{|l| File.expand_path("#{l}/#{EXE_NAME}") }.find{|location| File.exists? location}
45
+ exe_path || ''
46
+ end
25
47
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdftk
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Konrad Glowacki