Sha256: 445a4b3d5683d8c66c2bb64d5128cd89f8db6f5495314d0dea2b024055a36a80

Contents?: true

Size: 444 Bytes

Versions: 10

Compression:

Stored size: 444 Bytes

Contents

class File

  # Cleans up a filename to ensure it will work on a filesystem.
  #
  #   File.sanitize("yo+baby!")   #=> 'yo+baby_'
  #   File.sanitize(".what&up")  #=> '.what_up'
  #
  # CREDIT: George Moschovitis

  def self.sanitize(filename)
    filename = File.basename(filename.gsub("\\", "/")) # work-around for IE
    filename.gsub!(/[^a-zA-Z0-9\.\-\+_]/,"_")
    filename = "_#{filename}" if filename =~ /^\.+$/
    filename
  end

end

Version data entries

10 entries across 9 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/file/sanitize.rb
facets-3.1.0 lib/core/facets/file/sanitize.rb
facets-3.0.0 lib/core/facets/file/sanitize.rb
facets-2.9.3 lib/core/facets/file/sanitize.rb
facets-2.9.2 src/core/facets/file/sanitize.rb
facets-2.9.2 lib/core/facets/file/sanitize.rb
facets-2.9.1 lib/core/facets/file/sanitize.rb
facets-2.9.0 lib/core/facets/file/sanitize.rb
facets-2.9.0.pre.2 lib/core/facets/file/sanitize.rb
facets-2.9.0.pre.1 lib/core/facets/file/sanitize.rb