Class: RubySpriter::Platform

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_spriter/platform.rb

Overview

Platform detection and configuration

Constant Summary collapse

PLATFORM_TYPE =
case RUBY_PLATFORM
when /mingw|mswin|windows/i then :windows
when /linux/i then :linux
when /darwin/i then :macos
else :unknown
end
GIMP_DEFAULT_PATHS =

GIMP executable paths by platform

{
  windows: 'C:\\Program Files\\GIMP 3\\bin\\gimp-console-3.0.exe',
  linux: '/usr/bin/gimp',
  macos: '/Applications/GIMP.app/Contents/MacOS/gimp'
}.freeze
GIMP_ALTERNATIVE_PATHS =

Alternative GIMP paths to search

{
  windows: [
    'C:\\Program Files\\GIMP 3\\bin\\gimp-console-3.0.exe',
    'C:\\Program Files (x86)\\GIMP 3\\bin\\gimp-console-3.0.exe',
    'C:\\Program Files\\GIMP 2\\bin\\gimp-console-2.10.exe',
    'C:\\Program Files (x86)\\GIMP 2\\bin\\gimp-console-2.10.exe'
  ].freeze,
  linux: [
    '/usr/bin/gimp',
    '/usr/local/bin/gimp',
    '/snap/bin/gimp',
    '/opt/gimp/bin/gimp',
    'flatpak:org.gimp.GIMP'  # Flatpak GIMP
  ].freeze,
  macos: [
    '/Applications/GIMP.app/Contents/MacOS/gimp',
    '/Applications/GIMP-2.99.app/Contents/MacOS/gimp',  # GIMP 3.x dev
    '/Applications/GIMP-3.0.app/Contents/MacOS/gimp',   # GIMP 3.x release
    '/Applications/GIMP-2.10.app/Contents/MacOS/gimp'
  ].freeze
}.freeze

Class Method Summary collapse

Class Method Details

.alternative_gimp_pathsObject

Get alternative GIMP paths for current platform



70
71
72
# File 'lib/ruby_spriter/platform.rb', line 70

def alternative_gimp_paths
  GIMP_ALTERNATIVE_PATHS[PLATFORM_TYPE] || []
end

.currentObject

Get the current platform type



45
46
47
# File 'lib/ruby_spriter/platform.rb', line 45

def current
  PLATFORM_TYPE
end

.default_gimp_pathObject

Get default GIMP path for current platform



65
66
67
# File 'lib/ruby_spriter/platform.rb', line 65

def default_gimp_path
  GIMP_DEFAULT_PATHS[PLATFORM_TYPE]
end

.detect_gimp_version(version_output) ⇒ Hash

Detect GIMP version from version string output

Parameters:

  • version_output (String)

    Output from gimp –version command

Returns:

  • (Hash)

    Version information with :major, :minor, :patch, :full keys, or nil if parse fails



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/ruby_spriter/platform.rb', line 87

def detect_gimp_version(version_output)
  return nil if version_output.nil? || version_output.empty?

  # Match version pattern: "version X.Y.Z" or "version X.Y"
  match = version_output.match(/version\s+(\d+)\.(\d+)(?:\.(\d+))?/i)
  return nil unless match

  {
    major: match[1].to_i,
    minor: match[2].to_i,
    patch: match[3]&.to_i || 0,
    full: match[1..3].compact.join('.')
  }
end

.get_gimp_version(gimp_path) ⇒ Hash

Get GIMP version from executable path

Parameters:

  • gimp_path (String)

    Path to GIMP executable or flatpak:app.id

Returns:

  • (Hash)

    Version information, or nil if detection fails



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/ruby_spriter/platform.rb', line 105

def get_gimp_version(gimp_path)
  return nil if gimp_path.nil? || gimp_path.empty?

  require 'open3'

  # Handle Flatpak GIMP
  if gimp_path.start_with?('flatpak:')
    flatpak_app = gimp_path.sub('flatpak:', '')
    stdout, stderr, status = Open3.capture3("flatpak run #{flatpak_app} --version")
    return nil unless status.success?
    return detect_gimp_version(stdout + stderr)
  end

  return nil unless File.exist?(gimp_path)

  stdout, stderr, status = Open3.capture3("#{quote_path_simple(gimp_path)} --version")
  return nil unless status.success?

  detect_gimp_version(stdout + stderr)
rescue StandardError
  nil
end

.imagemagick_convert_cmdObject

Get ImageMagick convert command name



75
76
77
# File 'lib/ruby_spriter/platform.rb', line 75

def imagemagick_convert_cmd
  windows? ? 'magick convert' : 'convert'
end

.imagemagick_identify_cmdObject

Get ImageMagick identify command name



80
81
82
# File 'lib/ruby_spriter/platform.rb', line 80

def imagemagick_identify_cmd
  windows? ? 'magick identify' : 'identify'
end

.linux?Boolean

Check if running on Linux

Returns:

  • (Boolean)


55
56
57
# File 'lib/ruby_spriter/platform.rb', line 55

def linux?
  PLATFORM_TYPE == :linux
end

.macos?Boolean

Check if running on macOS

Returns:

  • (Boolean)


60
61
62
# File 'lib/ruby_spriter/platform.rb', line 60

def macos?
  PLATFORM_TYPE == :macos
end

.windows?Boolean

Check if running on Windows

Returns:

  • (Boolean)


50
51
52
# File 'lib/ruby_spriter/platform.rb', line 50

def windows?
  PLATFORM_TYPE == :windows
end