Class: RubySpriter::Utils::PathHelper

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

Overview

Cross-platform path handling utilities

Class Method Summary collapse

Class Method Details

.normalize_for_python(path) ⇒ String

Normalize path for Python scripts (GIMP)

Parameters:

  • path (String)

    The path to normalize

Returns:

  • (String)

    Normalized path with forward slashes



35
36
37
38
39
40
41
42
43
44
# File 'lib/ruby_spriter/utils/path_helper.rb', line 35

def normalize_for_python(path)
  abs_path = File.absolute_path(path)
  
  if Platform.windows?
    # Use forward slashes for Python raw strings
    abs_path.gsub('\\', '/')
  else
    abs_path
  end
end

.quote_arg(arg) ⇒ String

Quote a command argument for shell execution

Parameters:

  • arg (String)

    The argument to quote

Returns:

  • (String)

    Properly quoted argument



23
24
25
26
27
28
29
30
# File 'lib/ruby_spriter/utils/path_helper.rb', line 23

def quote_arg(arg)
  if Platform.windows?
    "\"#{arg}\""
  else
    # Need 4 backslashes because gsub interprets backslashes in replacement string
    "'#{arg.gsub("'", "\\\\'")}'"
  end
end

.quote_path(path) ⇒ String

Quote a file path for shell execution

Parameters:

  • path (String)

    The path to quote

Returns:

  • (String)

    Properly quoted path



11
12
13
14
15
16
17
18
# File 'lib/ruby_spriter/utils/path_helper.rb', line 11

def quote_path(path)
  if Platform.windows?
    "\"#{path}\""
  else
    # Need 4 backslashes because gsub interprets backslashes in replacement string
    "'#{path.gsub("'", "\\\\'")}'"
  end
end

.to_native(path) ⇒ String

Convert path to native format

Parameters:

  • path (String)

    The path to convert

Returns:

  • (String)

    Path with platform-appropriate separators



49
50
51
52
53
54
55
# File 'lib/ruby_spriter/utils/path_helper.rb', line 49

def to_native(path)
  if Platform.windows?
    path.gsub('/', '\\')
  else
    path.gsub('\\', '/')
  end
end