Sha256: d74f8c6113c515b78eb2b155956efa0dbeb520820dc66d95c1138b88fbd1422c

Contents?: true

Size: 1.01 KB

Versions: 12

Compression:

Stored size: 1.01 KB

Contents

class Downloadable < ActiveRecord::Base
  belongs_to :index
  attr_accessible :name, :description, :asset, :asset_file_name, :asset_content_type, :asset_file_size, :owner_id, :owner_type

  include ActsAsPrioritizable
  acts_as_prioritizable("index", "assets")

  has_attached_file :asset,
    :storage => :s3,
    :s3_credentials => Rails.root.join("config", "s3.yml"),
    :bucket => APP_CONFIG[:bucket_name],
    :path => "/downloadables/#{Rails.env}/:id/:filename"

  before_post_process :transliterate_file_name

  def thumb
    asset.url(:thumb)
  end

  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

  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
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
sbdevcore-0.1.2 app/models/downloadable.rb
sbdevcore-0.1.1 app/models/downloadable.rb
sbdevcore-0.1.0 app/models/downloadable.rb
sbdevcore-0.0.9 app/models/downloadable.rb
sbdevcore-0.0.8 app/models/downloadable.rb
sbdevcore-0.0.7 app/models/downloadable.rb
sbdevcore-0.0.6 app/models/downloadable.rb
sbdevcore-0.0.5 app/models/downloadable.rb
sbdevcore-0.0.4 app/models/downloadable.rb
sbdevcore-0.0.3 app/models/downloadable.rb
sbdevcore-0.0.1 app/models/downloadable.rb
sbdev-core-0.0.1 app/models/downloadable.rb