Class: Tahweel::PopplerInstaller

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.

Raises:

  • (SystemExit)

    if Poppler is missing on non-Windows platforms.



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_pathString

Returns the path to the pdfinfo executable.

Returns:

  • (String)

    path to the executable.



48
# File 'lib/tahweel/poppler_installer.rb', line 48

def self.pdfinfo_path = new.pdfinfo_path

.pdftoppm_pathString

Returns the path to the pdftoppm executable.

Returns:

  • (String)

    path to the 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).

Returns:

  • (Boolean)

    true if cached binaries exist.



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

#installObject

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.

Returns:

  • (Boolean)

    true if pdftoppm and pdfinfo are in the PATH or cached.



67
# File 'lib/tahweel/poppler_installer.rb', line 67

def installed? = (command_exists?("pdftoppm") && command_exists?("pdfinfo")) || cached?

#pdfinfo_pathString

Resolves the path to the pdfinfo executable.

Prioritizes the system PATH, falling back to the cached version on Windows.

Returns:

  • (String)

    path to pdfinfo.



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_pathString

Resolves the path to the pdftoppm executable.

Prioritizes the system PATH, falling back to the cached version on Windows.

Returns:

  • (String)

    path to pdftoppm.



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