Class: Asset

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/asset.rb

Overview

Base Asset Class


Available Attributes: :type :name :body :filename :checksum :path :content_type :file_size :width :height :duration :bit_rate

Direct Known Subclasses

Document, ExternalService, Image, Video

Instance Method Summary collapse

Instance Method Details

#document?Boolean

Is the asset a document?

Returns:

  • (Boolean)


35
36
37
# File 'app/models/asset.rb', line 35

def document?
  self.type == "Document"
end

#extensionObject

Get the file type extension from the filename



53
54
55
56
57
# File 'app/models/asset.rb', line 53

def extension
  filename = File.extname(self.filename.to_s)
  filename[0] = '' # remove the dot, i.e. (.docx or .pptx)
  filename
end

#external_service?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/models/asset.rb', line 44

def external_service?
  self.type == "ExternalService"
end

#image?Boolean

Is the asset a image?

Returns:

  • (Boolean)


30
31
32
# File 'app/models/asset.rb', line 30

def image?
  self.type == "Image"
end

#update_asset_attributesObject

Add some custom attributes to the asset



60
61
62
63
64
65
66
67
# File 'app/models/asset.rb', line 60

def update_asset_attributes
  if !self.external_service? and self.present? and self.changed?
    self.content_type = self.filename.file.content_type
    self.file_size = self.filename.file.size
    self.width, self.height = `identify -format "%wx%h" #{self.filename.file.path}`.split(/x/) unless self.document? or self.width? or self.height?
    self.ratio = self.width.to_f / self.height.to_f if self.width.present? and self.height.present?
  end
end

#video?Boolean

Is the asset a video?

Returns:

  • (Boolean)


40
41
42
# File 'app/models/asset.rb', line 40

def video?
  self.type == "Video"
end