Class: Assetabler::Asset

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

Direct Known Subclasses

Document, ExternalService, Image, Video

Instance Method Summary collapse

Instance Method Details

#document?Boolean

Is the asset a document?

Returns:

  • (Boolean)


20
21
22
# File 'app/models/assetabler/asset.rb', line 20

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

#extensionObject

Get the file type extension from the filename



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

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)


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

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

#image?Boolean

Is the asset a image?

Returns:

  • (Boolean)


15
16
17
# File 'app/models/assetabler/asset.rb', line 15

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

#update_asset_attributesObject

Add some custom attributes to the asset



45
46
47
48
49
50
51
52
# File 'app/models/assetabler/asset.rb', line 45

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)


25
26
27
# File 'app/models/assetabler/asset.rb', line 25

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