Created
May 6, 2011 19:30
-
-
Save akasper/959622 to your computer and use it in GitHub Desktop.
A method for sizing an upload. Response to https://gist.github.com/959582
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SIZING_METHODS = {:enable_images? => :resize, :enable_videos? => :encode} | |
def size_upload | |
result = {:export => {use: []}} | |
return result unless self.uploads_enabled? | |
['', '_thumb'].each do |insert| | |
w = "upload#{insert}_width".to_sym | |
w? = "#{w}?".to_sym | |
h = "upload#{insert}_height".to_sym | |
h? = "#{h}?".to_sym | |
if self.send(w?) && self.send(h?) | |
SIZING_METHODS.each do |method, result_key| | |
if self.send(method) | |
result["#{result_key}#{insert}".to_sym] = { | |
width: self.send(w), | |
height: self.send(h) | |
} | |
end | |
end | |
end | |
SIZING_METHODS.each { |method, pushed_value| result[:export][:use].push(pushed_value.to_s).push("#{pushed_value}_thumb") if self.send(method) } | |
result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment