Class: WickedPdf::Binary

Inherits:
Object
  • Object
show all
Defined in:
lib/wicked_pdf/binary.rb

Constant Summary collapse

EXE_NAME =
'wkhtmltopdf'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(binary_path, default_version = WickedPdf::DEFAULT_BINARY_VERSION) ⇒ Binary

Returns a new instance of Binary.



9
10
11
12
13
14
15
16
# File 'lib/wicked_pdf/binary.rb', line 9

def initialize(binary_path, default_version = WickedPdf::DEFAULT_BINARY_VERSION)
  @path = binary_path || find_binary_path
  @default_version = default_version

  raise "Location of #{EXE_NAME} unknown" if @path.empty?
  raise "Bad #{EXE_NAME}'s path: #{@path}" unless File.exist?(@path)
  raise "#{EXE_NAME} is not executable" unless File.executable?(@path)
end

Instance Attribute Details

#default_versionObject (readonly)

Returns the value of attribute default_version.



7
8
9
# File 'lib/wicked_pdf/binary.rb', line 7

def default_version
  @default_version
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/wicked_pdf/binary.rb', line 7

def path
  @path
end

Instance Method Details

#parse_version_string(version_info) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/wicked_pdf/binary.rb', line 22

def parse_version_string(version_info)
  match_data = /wkhtmltopdf\s*(\d*\.\d*\.\d*\w*)/.match(version_info)
  if match_data && (match_data.length == 2)
    Gem::Version.new(match_data[1])
  else
    default_version
  end
end

#versionObject



18
19
20
# File 'lib/wicked_pdf/binary.rb', line 18

def version
  @version ||= retrieve_binary_version
end

#xvfb_run_pathObject

Raises:

  • (StandardError)


31
32
33
34
35
36
# File 'lib/wicked_pdf/binary.rb', line 31

def xvfb_run_path
  path = possible_binary_locations.map { |l| File.expand_path("#{l}/xvfb-run") }.find { |location| File.exist?(location) }
  raise StandardError, 'Could not find binary xvfb-run on the system.' unless path

  path
end