Module: Pushfile::Util

Included in:
Upload
Defined in:
lib/pushfile/util.rb

Instance Method Summary collapse

Instance Method Details

#filename(name) ⇒ Object

Make sure the file name is valid



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/pushfile/util.rb', line 5

def filename(name)
  # Replace space with underscore and downcase extension
  pre, dot, ext = name.rpartition('.')
  name = "#{pre.gsub(' ', '_')}.#{ext.downcase}"

  # Remove illegal characters
  # http://stackoverflow.com/questions/13517100/whats-the-difference-between-palpha-i-and-pl-i-in-ruby
  name = name.gsub(%r{[^\p{L}\-\_\.0-9]}, '')

  name
end