Class: HashThatTree::HashIt
- Inherits:
-
Object
- Object
- HashThatTree::HashIt
- Defined in:
- lib/hashit.rb
Overview
This class accepts a folder array and provides methods to iterate through all files in the folder creating a hash of each file within. The results are displayed to Standard Out in csv, html, json or standard format
Instance Attribute Summary collapse
-
#error_data ⇒ Object
the container for the files that could not be processed.
-
#file_data ⇒ Object
the container for the hashing results.
-
#folders ⇒ Object
path to folder containing files to hash.
-
#format ⇒ Object
the format to output the results to - standard, csv, html or json.
Instance Method Summary collapse
-
#create_hash_results ⇒ Object
results of the comparisson.
-
#initialize(options, folders) ⇒ HashIt
constructor
initialize the class with the folders to be processed.
-
#validate ⇒ Object
Validates the supplied folders ensuring they exist.
Constructor Details
#initialize(options, folders) ⇒ HashIt
initialize the class with the folders to be processed
17 18 19 20 21 22 23 |
# File 'lib/hashit.rb', line 17 def initialize(, folders ) @format = ['output'] @folders = folders @file_data = [] @error_data = [] validate end |
Instance Attribute Details
#error_data ⇒ Object
the container for the files that could not be processed
14 15 16 |
# File 'lib/hashit.rb', line 14 def error_data @error_data end |
#file_data ⇒ Object
the container for the hashing results
13 14 15 |
# File 'lib/hashit.rb', line 13 def file_data @file_data end |
#folders ⇒ Object
path to folder containing files to hash
12 13 14 |
# File 'lib/hashit.rb', line 12 def folders @folders end |
#format ⇒ Object
the format to output the results to - standard, csv, html or json
11 12 13 |
# File 'lib/hashit.rb', line 11 def format @format end |
Instance Method Details
#create_hash_results ⇒ Object
results of the comparisson
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hashit.rb', line 37 def create_hash_results @folders.each do |folder| Dir.foreach(folder) do |item| begin next if item == '.' or item == '..' fullfilename = File.(folder, item) the_hash = Digest::MD5.hexdigest(File.read(File.join(File.(folder), item.downcase))) @file_data << {:filename=>item, :folder=>folder, :filehash => the_hash} rescue @error_data << {:error=>"Skipped#{File.(folder, item)}"} end end end end |
#validate ⇒ Object
Validates the supplied folders ensuring they exist
26 27 28 29 30 31 32 33 |
# File 'lib/hashit.rb', line 26 def validate @folders.each do |item| if(item==nil) || (item=="") || !Dir.exists?(item) puts "a valid folder path is required as argument #{item}" exit end end end |