Module: AnotherUploader::Transliteration
- Included in:
- Upload
- Defined in:
- lib/another_uploader/transliteration.rb
Instance Method Summary collapse
Instance Method Details
#transliterate(s) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/another_uploader/transliteration.rb', line 3 def transliterate s # Lifted from permalink_fu by Rick Olsen # Escape string using string#encode (which replaced Iconv in Ruby 1.9.3), # downcae, then remove illegal characters and replace them with ’-’ s.encode('UTF-8', invalid: :replace, :undef => :replace, replace: '?').force_encoding('UTF-8') s.downcase! s.gsub!(/\'/, '') s.gsub!(/[^A-Za-z0-9]+/, ' ') s.strip! s.gsub!(/\ +/, '-') # set single or multiple spaces to a single dash s end |
#transliterate_file_name ⇒ Object
16 17 18 19 20 |
# File 'lib/another_uploader/transliteration.rb', line 16 def transliterate_file_name extension = File.extname(local_file_name).gsub(/^\.+/, '') filename = local_file_name.gsub(/\.#{extension}$/, '') local.instance_write(:file_name, "#{transliterate(filename)}.#{transliterate(extension)}") end |