Module: BlackStack::Strings::Misc
- Defined in:
- lib/functions.rb
Overview
Miscelaneus
Class Method Summary collapse
- 
  
    
      .sanitize_filename(filename)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    make a Ruby string safe for a filesystem. 
Class Method Details
.sanitize_filename(filename) ⇒ Object
make a Ruby string safe for a filesystem. References:
> stackoverflow.com/questions/1939333/how-to-make-a-ruby-string-safe-for-a-filesystem
> devblog.muziboo.com/2008/06/17/attachment-fu-sanitize-filename-regex-and-unicode-gotcha/
| 756 757 758 759 760 761 762 763 764 765 766 | # File 'lib/functions.rb', line 756 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 |