Module: BlackStack::Strings::Misc

Defined in:
lib/functions.rb

Overview


Miscelaneus

Class Method Summary collapse

Class Method Details

.sanitize_filename(filename) ⇒ Object



525
526
527
528
529
530
531
532
533
534
535
# File 'lib/functions.rb', line 525

def self.sanitize_filename(filename)
  ret = filename.strip do |name|
    # NOTE: File.basename doesn't work right with Windows paths on Unix
    # get only the filename, not the whole path
    name.gsub!(/^.*(\\|\/)/, '')

    # Strip out the non-ascii character
    name.gsub!(/[^0-9A-Za-z.\-]/, '_')
  end
  return ret
end