Class: WickedPdf::Binary
- Inherits:
-
Object
- Object
- WickedPdf::Binary
- Defined in:
- lib/wicked_pdf/binary.rb
Constant Summary collapse
- EXE_NAME =
'wkhtmltopdf'.freeze
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.
7 8 9 10 11 12 13 14 |
# File 'lib/wicked_pdf/binary.rb', line 7 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.
5 6 7 |
# File 'lib/wicked_pdf/binary.rb', line 5 def default_version @default_version end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/wicked_pdf/binary.rb', line 5 def path @path end |
Instance Method Details
#parse_version_string(version_info) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/wicked_pdf/binary.rb', line 20 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
16 17 18 |
# File 'lib/wicked_pdf/binary.rb', line 16 def version @version ||= retrieve_binary_version end |
#xvfb_run_path ⇒ Object
29 30 31 32 33 34 |
# File 'lib/wicked_pdf/binary.rb', line 29 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 |