Module: Etom::Hash

Defined in:
lib/etom/hasher.rb

Class Method Summary collapse

Class Method Details

.create_hashes_for_file(file) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/etom/hasher.rb', line 28

def self.create_hashes_for_file(file)
  File.open("#{file}.sha1","w") do |f|
      f << sha1(file)
    end

    File.open("#{file}.md5","w") do |f|
      f << md5(file)
    end
end

.create_hashes_for_files(dir) ⇒ Object



22
23
24
25
26
# File 'lib/etom/hasher.rb', line 22

def self.create_hashes_for_files(dir)
  Dir.glob(File.join("dir","*.{jar,xml}")).each do |file|
    create_hashes_for_file(file)
  end
end

.md5(file) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/etom/hasher.rb', line 12

def self.md5(file)
  digest = Digest::SHA1.new
  File.open(file, "r") do |f|
    digest.update f.read(8192) until f.eof
  end
  digest.hexdigest

  Digest::MD5.hexdigest(File.read(file))
end

.sha1(file) ⇒ Object



8
9
10
# File 'lib/etom/hasher.rb', line 8

def self.sha1(file)
  Digest::SHA1.hexdigest(File.read(file))
end