Class: Downloadable

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActsAsPrioritizable
Defined in:
app/models/downloadable.rb

Instance Method Summary collapse

Instance Method Details

#thumbObject



18
19
20
# File 'app/models/downloadable.rb', line 18

def thumb
  asset.url(:thumb)
end

#transliterate(str) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'app/models/downloadable.rb', line 22

def transliterate(str)
  s = Iconv.iconv('ascii//ignore//translit', 'utf-8', str).to_s
  s.downcase!
  s.gsub!(/'/, '')
  s.gsub!(/[^A-Za-z0-9]+/, ' ')
  s.strip!
  s.gsub!(/\ +/, '-')
  s
end

#transliterate_file_nameObject



32
33
34
35
36
# File 'app/models/downloadable.rb', line 32

def transliterate_file_name
  extension = File.extname(asset_file_name).gsub(/^\.+/, '')
  filename = asset_file_name.gsub(/\.#{extension}$/, '')
  self.asset.instance_write(:file_name, "#{transliterate(filename)}.#{transliterate(extension)}")
end