Class: Asset
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Asset
- 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
Instance Method Summary collapse
-
#document? ⇒ Boolean
Is the asset a document?.
-
#extension ⇒ Object
Get the file type extension from the filename.
- #external_service? ⇒ Boolean
-
#image? ⇒ Boolean
Is the asset a image?.
-
#update_asset_attributes ⇒ Object
Add some custom attributes to the asset.
-
#video? ⇒ Boolean
Is the asset a video?.
Instance Method Details
#document? ⇒ Boolean
Is the asset a document?
35 36 37 |
# File 'app/models/asset.rb', line 35 def document? self.type == "Document" end |
#extension ⇒ Object
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
44 45 46 |
# File 'app/models/asset.rb', line 44 def external_service? self.type == "ExternalService" end |
#image? ⇒ Boolean
Is the asset a image?
30 31 32 |
# File 'app/models/asset.rb', line 30 def image? self.type == "Image" end |
#update_asset_attributes ⇒ Object
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?
40 41 42 |
# File 'app/models/asset.rb', line 40 def video? self.type == "Video" end |