Sha256: f69bb52c69cf28f38764ab3a9b29633ddd6279d37111f0c48d7ab2317d466ae6

Contents?: true

Size: 1016 Bytes

Versions: 30

Compression:

Stored size: 1016 Bytes

Contents

# encoding: utf-8

require 'rake/common/classes'
require 'rake/helpers/digest'

module Rake
  module Delphi
    class HashTask < BasicTask
        def initialize(file, alg)
            @file = file
            @alg = alg
        end

        def digest
            if ['md5', 'sha1'].include?(@alg)
                require 'digest/' + @alg
                return eval("Digest::#{@alg.upcase}.file(@file).hexdigest.upcase")
            else
                return "%02X" % Digest::CRC32.file(@file).digest.to_i
            end
        end
    end

    class HashesTask < BasicTask
        def initialize(task, files, alg)
            super(task)
            @hashes = {}
            calc_hashes(files, alg)
        end

        def calc_hashes(files, alg)
            files = [files] unless files.kind_of?(Array)
            files.each do |f|
                @hashes[f] = { alg.upcase => HashTask.new(f, alg).digest }
            end
        end

        def to_hash
            @hashes
        end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
rake-delphi-0.0.14 lib/rake/common/hashtask.rb
rake-delphi-0.0.13 lib/rake/common/hashtask.rb
rake-delphi-0.0.12 lib/rake/common/hashtask.rb
rake-delphi-0.0.11 lib/rake/common/hashtask.rb
rake-delphi-0.0.9 lib/rake/common/hashtask.rb
rake-delphi-0.0.8 lib/rake/common/hashtask.rb
rake-delphi-0.0.7 lib/rake/common/hashtask.rb
rake-delphi-0.0.6 lib/rake/common/hashtask.rb
rake-delphi-0.0.5 lib/rake/common/hashtask.rb
rake-delphi-0.0.4 lib/rake/common/hashtask.rb