Skip to content

Instantly share code, notes, and snippets.

View ewoodh2o's full-sized avatar

Elliott Wood ewoodh2o

  • CallRail
  • Atlanta, GA
View GitHub Profile
@ewoodh2o
ewoodh2o / size_upload.rb
Created May 6, 2011 20:19 — forked from akasper/size_upload.rb
A method for sizing an upload. Response to https://gist.github.com/959582
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
def upload_sizing
result = {}
if uploads_enabled?
dims = lambda {|size| send("upload#{size}_width?") && send("upload#{size}_width?") ?
{ width: send("upload#{size}_width"), height: send("upload#{size}_width") } : nil
}
{:enable_images? => :resize, :enable_videos? => :encode}.each do |method, result_key|
['', '_thumb'].each do |size|