Class: CleanseFilename

Inherits:
Object
  • Object
show all
Defined in:
app/models/cleanse_filename.rb

Class Method Summary collapse

Class Method Details

.call(filename) ⇒ Object

downcase and replace all non-alphanumerics with '_'



9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/cleanse_filename.rb', line 9

def self.call(filename)
  tmp = (filename.to_s.downcase).split('.')
 if tmp.count == 2
    tmp[0].gsub(/[^A-Za-z0-9\.]/, '_') + '.' + tmp[1]
 else
  for i in 0..(tmp.length-1)
     name = tmp[i].gsub(/[^A-Za-z0-9\.]/, '_')
   end
   name.join('_') + '.' + tmp.last
 end
end