Class: Tahweel::PopplerInstaller
- Inherits:
-
Object
- Object
- Tahweel::PopplerInstaller
- Defined in:
- lib/tahweel/poppler_installer.rb
Overview
Handles the installation and path resolution for Poppler utilities.
On Windows, this class can automatically download and install the necessary binaries if they are not present. On other platforms, it provides instructions for manual installation.
Constant Summary collapse
- POPPLER_REPO_API =
"https://api.github.com/repos/oschwartz10612/poppler-windows/releases/latest"
Class Method Summary collapse
-
.ensure_installed! ⇒ Object
Ensures that Poppler utilities are installed.
-
.pdfinfo_path ⇒ String
Returns the path to the
pdfinfoexecutable. -
.pdftoppm_path ⇒ String
Returns the path to the
pdftoppmexecutable.
Instance Method Summary collapse
-
#cached? ⇒ Boolean
Checks if Poppler binaries are present in the local cache (Windows only).
-
#install ⇒ Object
Installs Poppler binaries on Windows.
-
#installed? ⇒ Boolean
Checks if Poppler utilities are available.
-
#pdfinfo_path ⇒ String
Resolves the path to the
pdfinfoexecutable. -
#pdftoppm_path ⇒ String
Resolves the path to the
pdftoppmexecutable.
Class Method Details
.ensure_installed! ⇒ Object
Ensures that Poppler utilities are installed.
On Windows: Installs Poppler locally if not found. On other platforms: Aborts with an error message if Poppler is missing.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tahweel/poppler_installer.rb', line 27 def self.ensure_installed! # rubocop:disable Metrics/MethodLength installer = new return if installer.installed? if Gem.win_platform? installer.install else abort " Error: Poppler utilities are not installed. Please install them:\n MacOS: `brew install poppler`\n Ubuntu: `sudo apt install poppler-utils`\n MSG\n end\nend\n" |
.pdfinfo_path ⇒ String
Returns the path to the pdfinfo executable.
48 |
# File 'lib/tahweel/poppler_installer.rb', line 48 def self.pdfinfo_path = new.pdfinfo_path |
.pdftoppm_path ⇒ String
Returns the path to the pdftoppm executable.
44 |
# File 'lib/tahweel/poppler_installer.rb', line 44 def self.pdftoppm_path = new.pdftoppm_path |
Instance Method Details
#cached? ⇒ Boolean
Checks if Poppler binaries are present in the local cache (Windows only).
72 73 74 75 76 |
# File 'lib/tahweel/poppler_installer.rb', line 72 def cached? return false unless Gem.win_platform? File.exist?(File.join(cached_bin_path, "pdftoppm.exe")) end |
#install ⇒ Object
Installs Poppler binaries on Windows.
Downloads the latest release from GitHub and extracts it to the cache directory. Does nothing if already installed.
54 55 56 57 58 59 60 61 62 |
# File 'lib/tahweel/poppler_installer.rb', line 54 def install zip_path = nil return if installed? zip_path = download_release_file extract_zip_file(zip_path) ensure FileUtils.rm_f(zip_path) if zip_path end |
#installed? ⇒ Boolean
Checks if Poppler utilities are available.
67 |
# File 'lib/tahweel/poppler_installer.rb', line 67 def installed? = (command_exists?("pdftoppm") && command_exists?("pdfinfo")) || cached? |
#pdfinfo_path ⇒ String
Resolves the path to the pdfinfo executable.
Prioritizes the system PATH, falling back to the cached version on Windows.
94 95 96 97 98 |
# File 'lib/tahweel/poppler_installer.rb', line 94 def pdfinfo_path return "pdfinfo" if command_exists?("pdfinfo") Gem.win_platform? ? File.join(cached_bin_path, "pdfinfo.exe") : nil end |
#pdftoppm_path ⇒ String
Resolves the path to the pdftoppm executable.
Prioritizes the system PATH, falling back to the cached version on Windows.
83 84 85 86 87 |
# File 'lib/tahweel/poppler_installer.rb', line 83 def pdftoppm_path return "pdftoppm" if command_exists?("pdftoppm") Gem.win_platform? ? File.join(cached_bin_path, "pdftoppm.exe") : nil end |