Class: WickedPdf::Binary
- Inherits:
-
Object
- Object
- WickedPdf::Binary
- Defined in:
- lib/wicked_pdf/binary.rb
Constant Summary collapse
- EXE_NAME =
'wkhtmltopdf'
Instance Attribute Summary collapse
-
#default_version ⇒ Object
readonly
Returns the value of attribute default_version.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(binary_path, default_version = WickedPdf::DEFAULT_BINARY_VERSION) ⇒ Binary
constructor
A new instance of Binary.
- #parse_version_string(version_info) ⇒ Object
- #version ⇒ Object
- #xvfb_run_path ⇒ Object
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_version ⇒ Object (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 |
#path ⇒ Object (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 |
#version ⇒ Object
18 19 20 |
# File 'lib/wicked_pdf/binary.rb', line 18 def version @version ||= retrieve_binary_version end |
#xvfb_run_path ⇒ Object
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.("#{l}/xvfb-run") }.find { |location| File.exist?(location) } raise StandardError, 'Could not find binary xvfb-run on the system.' unless path path end |