Class: CheckSumSerializer
Constant Summary collapse
- @@hash_filename =
"wm_bin_hash.txt"
- @@hash_filepath =
nil
Instance Method Summary collapse
- #cansave ⇒ Object
-
#initialize(filepath) ⇒ CheckSumSerializer
constructor
A new instance of CheckSumSerializer.
- #load ⇒ Object
- #save(hashes) ⇒ Object
Constructor Details
#initialize(filepath) ⇒ CheckSumSerializer
Returns a new instance of CheckSumSerializer.
9 10 11 |
# File 'lib/build/CheckSumCalculator.rb', line 9 def initialize(filepath) @@hash_filepath = File.join(filepath, @@hash_filename) end |
Instance Method Details
#cansave ⇒ Object
52 53 54 |
# File 'lib/build/CheckSumCalculator.rb', line 52 def cansave return !File.exists?(@@hash_filepath) end |
#load ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/build/CheckSumCalculator.rb', line 27 def load() loaded_hash = Array.new File.readlines(@@hash_filepath).each do |line| lines = line.each_line('|').to_a next if lines.length < 2 name = lines[0].chomp('|') md5 = lines[1].chomp('|') name = name.chomp md5 = md5.chomp line_hash = Hash.new line_hash["name"] = name.to_s line_hash["md5"] = md5.to_s loaded_hash << line_hash end puts "loaded hashes for " + loaded_hash.length.to_s + " files" loaded_hash end |
#save(hashes) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/build/CheckSumCalculator.rb', line 13 def save(hashes) puts "save hashes for " + hashes.length.to_s + " files" FileUtils.rm_f @@hash_filepath f = File.new(@@hash_filepath, "w+") hashes.each { |file| f.puts file["name"].to_s + "|" + file["md5"].to_s } f.close end |