Class: Assetabler::Asset
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Assetabler::Asset
- Defined in:
- app/models/assetabler/asset.rb
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?
20 21 22 |
# File 'app/models/assetabler/asset.rb', line 20 def document? self.type == "Assetabler::Document" end |
#extension ⇒ Object
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
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?
15 16 17 |
# File 'app/models/assetabler/asset.rb', line 15 def image? self.type == "Assetabler::Image" end |
#update_asset_attributes ⇒ Object
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?
25 26 27 |
# File 'app/models/assetabler/asset.rb', line 25 def video? self.type == "Assetabler::Video" end |