Sha256: bc2f0e8d2defd26776848c44581f59303f6c558e38b9f30c8d9c103a050d51d6

Contents?: true

Size: 752 Bytes

Versions: 3

Compression:

Stored size: 752 Bytes

Contents

require 'digest/sha1'
module Thumbs

  class Image

    attr_accessor :server, :path, :size

    def initialize(params)
      @size          = params[:size] if params[:size] =~ /^\d+x\d+$/
      @url           = params[:original_url]
      @thumbs_folder = params[:thumbs_folder]
    end

    def local_path(size)
      File.join(@thumbs_folder, spread(sha(size+@url))) if @thumbs_folder
    end
    
    def original_path
      local_path("original")
    end
    
    def resized_path
      local_path(@size)
    end
    
    def remote_url
      "http://#{@url}"
    end
    
    protected
      def sha(path)
        Digest::SHA1.hexdigest(path)
      end
      
      def spread(sha, n = 2)
        sha[2, 0] = "/"
        sha
      end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
thumbs-0.0.5 lib/thumbs/image.rb
thumbs-0.0.4 lib/thumbs/image.rb
thumbs-0.0.3 lib/thumbs/image.rb