Class: Gluttonberg::Asset
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Gluttonberg::Asset
show all
- Includes:
- Library::AttachmentMixin
- Defined in:
- app/models/gluttonberg/asset.rb
Constant Summary
- GIGA_SIZE =
constants for formatted file size
1073741824.0
- MEGA_SIZE =
1048576.0
- KILO_SIZE =
1024.0
Library::AttachmentMixin::DEFAULT_THUMBNAILS, Library::AttachmentMixin::MAX_IMAGE_SIZE
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
included
Class Method Details
+ (Object) clear_all_asset_types
82
83
84
85
86
87
|
# File 'app/models/gluttonberg/asset.rb', line 82
def self.clear_all_asset_types
all.each do |asset|
asset.asset_type = nil
asset.save
end
end
|
+ (Object) create_assets_from_ftp
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'app/models/gluttonberg/asset.rb', line 104
def self.create_assets_from_ftp
collection = AssetCollection.find_by_name("BULKS")
files = Dir.entries(RAILS_ROOT+"/bulks")
files.each do |entry|
unless entry.starts_with?(".") || entry.starts_with?("__")
file = MyFile2.init(entry)
asset_name_with_extention = entry.split(".").first
asset_params = {:name => asset_name_with_extention , :file => file }
@asset = Asset.create(asset_params.merge({:asset_collection_ids => collection.id.to_s}))
end
end
end
|
+ (Object) refresh_all_asset_types
75
76
77
78
79
80
|
# File 'app/models/gluttonberg/asset.rb', line 75
def self.refresh_all_asset_types
all.each do |asset|
asset.auto_set_asset_type
asset.save
end
end
|
Instance Method Details
- (Object) absolute_file_path
96
97
98
|
# File 'app/models/gluttonberg/asset.rb', line 96
def absolute_file_path
Rails.root.to_s + "/public" + self.url.to_s
end
|
- (Object) alt_or_title
23
24
25
26
27
28
29
|
# File 'app/models/gluttonberg/asset.rb', line 23
def alt_or_title
unless alt.blank?
alt
else
title
end
end
|
- (Object) auto_set_asset_type
65
66
67
68
69
70
71
72
73
|
# File 'app/models/gluttonberg/asset.rb', line 65
def auto_set_asset_type
self.asset_type = AssetType.for_file(mime_type, file_name)
cat = self.category.to_s.downcase
if cat == "image"
self[:type] = "Photo"
elsif cat == "video"
self[:type] = "Video"
end
end
|
- (Object) category
returns category of asset
32
33
34
35
36
37
38
|
# File 'app/models/gluttonberg/asset.rb', line 32
def category
if asset_type.nil? then
Library::UNCATEGORISED_CATEGORY
else
asset_type.asset_category.name
end
end
|
- (Object) filename_without_extension
100
101
102
|
# File 'app/models/gluttonberg/asset.rb', line 100
def filename_without_extension
self.file_name.split(".").first unless self.file_name.blank?
end
|
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'app/models/gluttonberg/asset.rb', line 52
def formatted_file_size
precision = 2
unless size.blank?
case
when size == 1 then "1 Byte"
when size < KILO_SIZE then "%d Bytes" % size
when size < MEGA_SIZE then "%.#{precision}f KB" % (size / KILO_SIZE)
when size < GIGA_SIZE then "%.#{precision}f MB" % (size / MEGA_SIZE)
else "%.#{precision}f GB" % (size / GIGA_SIZE)
end
end
end
|
- (Object) set_category_and_type
find out and set type and category of file
90
91
92
93
94
|
# File 'app/models/gluttonberg/asset.rb', line 90
def set_category_and_type
unless file.nil?
auto_set_asset_type
end
end
|
- (Object) title
40
41
42
|
# File 'app/models/gluttonberg/asset.rb', line 40
def title
self.name
end
|
- (Object) type_name
44
45
46
47
48
49
50
|
# File 'app/models/gluttonberg/asset.rb', line 44
def type_name
if asset_type.nil? then
Library::UNCATEGORISED_CATEGORY
else
asset_type.name
end
end
|