class Avatar < ActiveRecord::Base # Image directories URL_STUB = "/images/avatars" DIRECTORY = File.join("public", "images", "avatars") def initialize(user, image = nil) @user = user @image = image Dir.mkdir(DIRECTORY) unless File.directory?(DIRECTORY) end def exists? File.exists?(File.join(DIRECTORY, filename)) end def exist? exists? end def url "#{URL_STUB}/#{filename}" end def thumbnail_url "#{URL_STUB}/#{thumbnail_name}" end private # Return the filename of the main avatar. def filename "#{@user.screen_name}.png" end # Return the filename of the avatar thumbnail. def thumbnail_name "#{@user.screen_name}_thumbnail.png" end # Return the (system-dependent) ImageMagick convert executable. def convert if ENV["OS"] =~ /Windows/ # Set this to point to the right Windows directory for ImageMagick. "C:\\Program Files\\ImageMagick-6.3.1-Q16\\convert" else "/usr/bin/convert" end end end