Class: PushType::Asset
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- PushType::Asset
show all
- Includes:
- Trashable
- Defined in:
- app/models/push_type/asset.rb
Instance Method Summary
collapse
Methods included from Trashable
#restore!, #trash!, #trashed?
Instance Method Details
#description_or_file_name ⇒ Object
54
55
56
|
# File 'app/models/push_type/asset.rb', line 54
def description_or_file_name
description? ? description : file_name
end
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'app/models/push_type/asset.rb', line 20
def kind
return nil unless file_stored?
case mime_type
when /\/vnd\.adobe/ then :file
when /\Aaudio\/.*\z/ then :audio
when /\Aimage\/.*\z/ then :image
when /\Avideo\/.*\z/ then :video
when /\/vnd.*wordprocessingml/,
/\/vnd\.msword\z/,
/\Atext\/(plain|rtf)\z/ then :doc
when /\/pdf\z/ then :pdf
when /\/vnd.*spreadsheetml/,
/\/vnd\.ms-excel\z/ then :sheet
when /\/vnd.*presentationml/,
/\/vnd\.ms-powerpoint\z/ then :slides
when /\/(css|html|javascript|json)\z/,
/\/.*xml.*\z/ then :code
when /\/csv\z/ then :csv
when /\/(g?zip|x.+compressed)\z/ then :zip
else :file
end
end
|
58
59
60
61
62
63
64
65
66
67
68
|
# File 'app/models/push_type/asset.rb', line 58
def media(style = nil)
return file if !image? || svg? || style.blank?
case style.to_sym
when :original then file
when :push_type_thumb then preview_thumb
else
size = PushType.config.media_styles[style.to_sym] || style
file.thumb(size)
end
end
|
#preview_thumb(size = '300x300') ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
|
# File 'app/models/push_type/asset.rb', line 70
def preview_thumb(size = '300x300')
return unless image?
width, height = size.split('x').map(&:to_i)
if file.width >= width && file.height >= height
file.thumb("#{ size }#")
else
file.convert("-background white -gravity center -extent #{ size }")
end
end
|
#svg? ⇒ Boolean
50
51
52
|
# File 'app/models/push_type/asset.rb', line 50
def svg?
mime_type =~ /\Aimage\/svg/
end
|