Module: Thumbo
- Defined in:
- lib/thumbo.rb,
lib/thumbo/proxy.rb,
lib/thumbo/version.rb,
lib/thumbo/storages/abstract.rb,
lib/thumbo/storages/mogilefs.rb,
lib/thumbo/storages/filesystem.rb,
lib/thumbo/exceptions/file_not_found.rb
Defined Under Namespace
Modules: ClassMethod
Classes: AbstractStorage, FileNotFound, Filesystem, Mogilefs, Proxy
Constant Summary
collapse
- VERSION =
'0.6.0'
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.calculate_dimension(limit, width, height) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/thumbo.rb', line 10
def self.calculate_dimension limit, width, height
long, short = width >= height ? [width, height] : [height, width]
if long <= limit [width, height]
elsif width == height [limit, limit]
else
new_width, new_height = limit, short * (limit.to_f / long)
new_width, new_height = new_height, new_width if long == height
[new_width, new_height]
end
end
|
.included(model) ⇒ Object
6
7
8
|
# File 'lib/thumbo.rb', line 6
def self.included model
model.extend(Thumbo::ClassMethod)
end
|
Instance Method Details
#create_thumbos(after_scale = lambda{}, &block) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/thumbo.rb', line 69
def create_thumbos after_scale = lambda{}, &block
after_scale = block if block_given?
self.class.thumbo_common.merge(self.class.thumbo_square).each_key{ |title|
after_scale[ thumbos[title].create ]
}
after_scale[ thumbos[:original] ]
self
end
|
#thumbo_filename(thumbo) ⇒ Object
56
57
58
|
# File 'lib/thumbo.rb', line 56
def thumbo_filename thumbo
"#{object_id}_#{thumbo.title}.#{thumbo.fileext}"
end
|
#thumbo_mime_type ⇒ Object
65
66
67
|
# File 'lib/thumbo.rb', line 65
def thumbo_mime_type
thumbos[:original].mime_type
end
|
#thumbo_uri(thumbo) ⇒ Object
60
61
62
63
|
# File 'lib/thumbo.rb', line 60
def thumbo_uri thumbo
paths = thumbo.paths
paths[rand(paths.size)]
end
|
#thumbos ⇒ Object
52
53
54
|
# File 'lib/thumbo.rb', line 52
def thumbos
@thumbos ||= init_thumbos
end
|