hash-that-tree 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1,19 +1,19 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- coverage
6
- InstalledFiles
7
- lib/bundler/man
8
- pkg
9
- rdoc
10
- spec/reports
11
- test/tmp
12
- test/version_tmp
13
- tmp
14
- doc
15
- # YARD artifacts
16
- .yardoc
17
- _yardoc
18
- .project
19
- *~
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+ doc
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ .project
19
+ *~
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in hash-that-tree.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hash-that-tree.gemspec
4
+ gemspec
@@ -1,21 +1,21 @@
1
- PATH
2
- remote: .
3
- specs:
4
- hash-that-tree (0.1.4)
5
- mustache
6
- thor
7
- yard
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- mustache (0.99.4)
13
- thor (0.16.0)
14
- yard (0.8.3)
15
-
16
- PLATFORMS
17
- ruby
18
- x86-mingw32
19
-
20
- DEPENDENCIES
21
- hash-that-tree!
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hash-that-tree (0.1.4)
5
+ mustache
6
+ thor
7
+ yard
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ mustache (0.99.4)
13
+ thor (0.16.0)
14
+ yard (0.8.3)
15
+
16
+ PLATFORMS
17
+ ruby
18
+ x86-mingw32
19
+
20
+ DEPENDENCIES
21
+ hash-that-tree!
@@ -1,22 +1,22 @@
1
- Copyright (c) 2012 John Ryan
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
1
+ Copyright (c) 2012 John Ryan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,77 +1,83 @@
1
- #hash-that-tree
2
- A ruby command line app prints the MD5 hashes all of the files in an array of folders.
3
- The output can be in standard text, csv, html or json.
4
-
5
- Also has a compare functionthat takes 2 folder, then iterates through the files and comparing the MD5 hashes of the files with the same name
6
-
7
- ## Usage
8
- # to view help
9
- hashthattree help
10
-
11
- # Get the hash of all files in a folder (with optional formatting)
12
- hashthattree hashit ./spec/testfiles/1
13
- hashthattree hashit ./spec/testfiles/1 -o=csv
14
- hashthattree hashit ./spec/testfiles/1 -o=html
15
- hashthattree hashit ./spec/testfiles/1 -o=json
16
-
17
- # Get the hash of all files in multiple folders
18
- hashthattree hashit ./spec/testfiles/1
19
-
20
- # run the app on the test files in two folders (this will soon be depreciated)
21
- hashthattree compare ./spec/testfiles/1 ./spec/testfiles/2
22
- hashthattree compare ./spec/testfiles/1 ./spec/testfiles/2 csv
23
- hashthattree compare ./spec/testfiles/1 ./spec/testfiles/2 html
24
- hashthattree compare ./spec/testfiles/1 ./spec/testfiles/2 json
25
-
26
- ## Installation
27
-
28
- Add this line to your application's Gemfile:
29
-
30
- gem 'hash-that-tree'
31
-
32
- And then execute:
33
-
34
- $ bundle
35
-
36
- Or install it yourself as:
37
-
38
- $ gem install hash-that-tree
39
-
40
- ## Creating Documentation
41
- Run the following command to generate the documantation
42
-
43
- rdoc --exclude spec/testfiles
44
-
45
- ## Create a gem
46
-
47
- Build and Test Locally
48
- -gem build hash-that-tree.gemspec
49
- -gem install hash-that-tree-X.X.X # where X.X.X is the version of the compiled gemspec
50
- -hashthattree
51
-
52
- Build and deploy to rubygems.org
53
- -gem update --system
54
- -gem build hash-that-tree.gemspec
55
- -gem push hash-that-tree-0.0.1.gem # where X.X.X is the version of the compiled gemspec
56
-
57
- ## Contributing
58
-
59
- 1. Fork it
60
- 2. Create your feature branch (`git checkout -b my-new-feature`)
61
- 3. Commit your changes (`git commit -am 'Add some feature'`)
62
- 4. Push to the branch (`git push origin my-new-feature`)
63
- 5. Create new Pull Request
64
-
65
- ##References
66
-
67
- Looking into bundling with https://github.com/radar/guides/blob/master/gem-development.md
68
- http://whatisthor.com/
69
-
70
- ## TODO
71
-
72
- I have a few items to do in upcoming releases
73
- * Add Unit Tests
74
- * Allow to be used as an API as well as a Command Line Tool
75
- * Add folder recursion option
76
- * Add SHA1
77
-
1
+ #hash-that-tree
2
+ A ruby command line app prints the MD5 hashes all of the files in an array of folders.
3
+ The output can be in standard text, csv, html or json.
4
+
5
+ Also has a compare functionthat takes 2 folder, then iterates through the files and comparing the MD5 hashes of the files with the same name
6
+
7
+ ## Usage
8
+ # to view help
9
+ hashthattree help
10
+
11
+ # Get the hash of all files in a folder (with optional formatting)
12
+ hashthattree hashit ./spec/testfiles/1
13
+ hashthattree hashit ./spec/testfiles/1 -o=csv
14
+ hashthattree hashit ./spec/testfiles/1 -o=html
15
+ hashthattree hashit ./spec/testfiles/1 -o=json
16
+
17
+ # Get the hash of all files in multiple folders
18
+ hashthattree hashit ./spec/testfiles/1
19
+
20
+ # run the app on the test files in two folders (this will soon be depreciated)
21
+ hashthattree compare ./spec/testfiles/1 ./spec/testfiles/2
22
+ hashthattree compare ./spec/testfiles/1 ./spec/testfiles/2 csv
23
+ hashthattree compare ./spec/testfiles/1 ./spec/testfiles/2 html
24
+ hashthattree compare ./spec/testfiles/1 ./spec/testfiles/2 json
25
+
26
+ ## Installation
27
+
28
+ Add this line to your application's Gemfile:
29
+
30
+ gem 'hash-that-tree'
31
+
32
+ And then execute:
33
+
34
+ $ bundle
35
+
36
+ Or install it yourself as:
37
+
38
+ $ gem install hash-that-tree
39
+
40
+ ## Creating Documentation
41
+ Run the following command to generate the documantation
42
+
43
+ rdoc --exclude spec/testfiles
44
+
45
+ ## Create a gem
46
+
47
+ Build and Test Locally
48
+ -gem build hash-that-tree.gemspec
49
+ -gem install hash-that-tree-X.X.X # where X.X.X is the version of the compiled gemspec
50
+ -hashthattree
51
+
52
+ Build and deploy to rubygems.org
53
+ -gem update --system
54
+ -gem build hash-that-tree.gemspec
55
+ -gem push hash-that-tree-0.0.1.gem # where X.X.X is the version of the compiled gemspec
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create new Pull Request
64
+
65
+ ##References
66
+
67
+ Looking into bundling with https://github.com/radar/guides/blob/master/gem-development.md
68
+ http://whatisthor.com/
69
+
70
+ ## TODO
71
+
72
+ I have a few items to do in upcoming releases
73
+
74
+ - [x] Add MD5
75
+ - [x] Allow for single or multiple folders
76
+ - [x] Format output in json
77
+ - [x] Format output in html
78
+ - [x] Format output in csv
79
+ -[ ] Add Unit Tests
80
+ -[ ] Allow to be used as an API as well as a Command Line Tool
81
+ -[ ] Add folder recursion option
82
+ -[ ] Add SHA1
83
+
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
@@ -1 +1 @@
1
- require_relative '../lib/cli'
1
+ require_relative '../lib/cli'
@@ -1,27 +1,27 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
-
5
- Gem::Specification.new do |gem|
6
- gem.name = %q{hash-that-tree}
7
- gem.version = "0.1.4"
8
- gem.authors = ["John Ryan"]
9
- gem.email = ["555john@gmail.com"]
10
- gem.description = %q{Command line app that produces the MD5 hash of all files in a set of folders}
11
- gem.summary = %q{A ruby command line app prints the MD5 hashes all of the files in an array of folders, the output can be in standard text, csv, html or json}
12
- gem.homepage = %q{http://github.com/jnyryan/hash-that-tree}
13
-
14
- gem.extra_rdoc_files = ["LICENSE.txt","README.md" ]
15
- gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
- gem.executable = 'hashthattree'
18
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
- gem.require_paths = ["lib"]
20
-
21
- gem.rdoc_options << '--exclude spec/testfiles'
22
-
23
- gem.add_dependency "mustache"
24
- gem.add_dependency "thor"
25
- gem.add_dependency "yard"
26
-
27
- end
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = %q{hash-that-tree}
7
+ gem.version = "0.1.5"
8
+ gem.authors = ["John Ryan"]
9
+ gem.email = ["555john@gmail.com"]
10
+ gem.description = %q{Command line app that produces the MD5 hash of all files in a set of folders}
11
+ gem.summary = %q{A ruby command line app prints the MD5 hashes all of the files in an array of folders, the output can be in standard text, csv, html or json}
12
+ gem.homepage = %q{http://github.com/patchapps/hash-that-tree}
13
+
14
+ gem.extra_rdoc_files = ["LICENSE.txt","README.md" ]
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.executable = 'hashthattree'
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.rdoc_options << '--exclude spec/testfiles'
22
+
23
+ gem.add_dependency "mustache"
24
+ gem.add_dependency "thor"
25
+ gem.add_dependency "yard"
26
+
27
+ end
data/lib/cli.rb CHANGED
@@ -1,36 +1,36 @@
1
- require 'thor'
2
- require_relative 'compare'
3
- require_relative 'hashit'
4
- require_relative 'display'
5
-
6
- # Command Line Program that takes multiple directories and creates a MD5 hash for every file contained within.<br/>
7
- # It then builds a result set that compares files with the same name and allows for them to be outputted
8
- # as a csv string
9
- module HashThatTree
10
- #This class controls the Command Line Interface
11
- class CLI < Thor
12
- #Create a hash of all files in the folders, compare them and output the results in CSV format
13
- desc "compare FOLDER1 FOLDER2", "Create a hash of all files in the folders, compare them and output the results in the specified format"
14
- method_option :output, :aliases => "-o", :default => :csv, :desc => "Choose the format to display the results in - csv, json or html"
15
- def compare(folder1, folder2)
16
- htt = CompareMD5.new(folder1, folder2, options)
17
- htt.compare
18
- htt.display_results
19
- end
20
-
21
- desc "hashit FOLDERS", "Create a hash of all files in all folders supplied and display as standard, json, csv or html"
22
- method_option :errors, :aliases => "-e", :type => :boolean, :default => false, :desc => "true = display files that could not be processed, false = do not display skipped files"
23
- #method_option :hashtype, :aliases => "-h", :default => "cmd5", :desc => "Choose the hash algorithm to use - md5 or sha"
24
- method_option :output, :aliases => "-o", :default => "standard", :desc => "Choose the format to display the results in - standard(default), csv, json or html"
25
- #method_option :recursive, :aliases => "-r", :type => :boolean, :default => "false", :desc => "true = recurse through sub directories, false = only do top directory"
26
- def hashit(*folders)
27
- htt = HashIt.new(options, folders)
28
- htt.create_hash_results
29
- dis = Display.new(options, htt.error_data, htt.file_data)
30
- dis.display_results()
31
- end
32
-
33
- end
34
- #CLI.start(ARGV)
35
- CLI.start()
1
+ require 'thor'
2
+ require_relative 'compare'
3
+ require_relative 'hashit'
4
+ require_relative 'display'
5
+
6
+ # Command Line Program that takes multiple directories and creates a MD5 hash for every file contained within.<br/>
7
+ # It then builds a result set that compares files with the same name and allows for them to be outputted
8
+ # as a csv string
9
+ module HashThatTree
10
+ #This class controls the Command Line Interface
11
+ class CLI < Thor
12
+ #Create a hash of all files in the folders, compare them and output the results in CSV format
13
+ desc "compare FOLDER1 FOLDER2", "Create a hash of all files in the folders, compare them and output the results in the specified format"
14
+ method_option :output, :aliases => "-o", :default => :csv, :desc => "Choose the format to display the results in - csv, json or html"
15
+ def compare(folder1, folder2)
16
+ htt = CompareMD5.new(folder1, folder2, options)
17
+ htt.compare
18
+ htt.display_results
19
+ end
20
+
21
+ desc "hashit FOLDERS", "Create a hash of all files in all folders supplied and display as standard, json, csv or html"
22
+ method_option :errors, :aliases => "-e", :type => :boolean, :default => false, :desc => "true = display files that could not be processed, false = do not display skipped files"
23
+ #method_option :hashtype, :aliases => "-h", :default => "cmd5", :desc => "Choose the hash algorithm to use - md5 or sha"
24
+ method_option :output, :aliases => "-o", :default => "standard", :desc => "Choose the format to display the results in - standard(default), csv, json or html"
25
+ #method_option :recursive, :aliases => "-r", :type => :boolean, :default => "false", :desc => "true = recurse through sub directories, false = only do top directory"
26
+ def hashit(*folders)
27
+ htt = HashIt.new(options, folders)
28
+ htt.create_hash_results
29
+ dis = Display.new(options, htt.error_data, htt.file_data)
30
+ dis.display_results()
31
+ end
32
+
33
+ end
34
+ #CLI.start(ARGV)
35
+ CLI.start()
36
36
  end
@@ -1,120 +1,120 @@
1
- require 'digest/md5'
2
-
3
- # Author:: John Ryan (mailto:555john@gmail.com)
4
- # Copyright:: Copyright (c) 2012 John Ryan
5
- # License:: Distributes under the same terms as Ruby
6
-
7
- module HashThatTree
8
-
9
- # This class accepts two folders and provides methods to iterate
10
- # through them creating a hash of each file within and can display
11
- # the results for analysis
12
- class CompareMD5
13
- attr_accessor :folder1 #path to folder containing files to hash
14
- attr_accessor :folder2 #path to folder containing files to hash to be compared to folder1
15
- attr_accessor :format #the format to output the results to. csv, html or json
16
-
17
- #initialize the class with the folders to be compared
18
- def initialize(folder1, folder2, options)
19
- @folder1 = folder1
20
- @folder2 = folder2
21
- @format = options['output']
22
- @filehash = Hash.new
23
- validate
24
- end
25
-
26
-
27
- # Validates the input ensuring the arguments are both valid folders
28
- def validate
29
- if(folder1==nil) || (folder1=="") || !Dir.exists?(folder1)
30
- puts "a valid folder path is required as argument 1"
31
- exit
32
- end
33
-
34
- if(folder2==nil) || (folder2=="") || !Dir.exists?(folder2)
35
- puts "a valid folder path is required as argument 2"
36
- exit
37
- end
38
-
39
- end
40
-
41
- # Iterates through the folders and creates a FileHashResults object containing the
42
- # results of the comparisson
43
- def compare
44
-
45
- Dir.foreach(@folder1) do |item|
46
- begin
47
- next if item == '.' or item == '..'
48
- fullfilename = File.expand_path(@folder1, item)
49
- the_hash = Digest::MD5.hexdigest(File.read(File.join(File.expand_path(@folder1), item)))
50
- item = item.downcase
51
- filedata = FileHashResults.new(item, the_hash, nil)
52
- @filehash[item] = filedata
53
- rescue
54
- #puts "Skipped:#{item.inspect}"
55
- end
56
- end
57
-
58
- Dir.foreach(@folder2) do |item|
59
- begin
60
- next if item == '.' or item == '..'
61
- the_hash = Digest::MD5.hexdigest(File.read(File.join(@folder2, item)))
62
- item = item.downcase
63
- if(@filehash[item]==nil)
64
- filedata = FileHashResults.new(item, nil, the_hash)
65
- @filehash[item] = filedata
66
- next
67
- end
68
- @filehash[item.downcase].file_hash2 = the_hash
69
- rescue
70
- #puts "Skipped:#{item.inspect}"
71
- end
72
- end
73
- end
74
-
75
- #print the contents of the FileHashResults object standard out in the format specified. Default is csv
76
- def display_results()
77
- case @format
78
- when "csv"
79
- display_results_csv
80
- when "html"
81
- display_results_html
82
- when "json"
83
- display_results_json
84
- else
85
- display_results_csv
86
- end
87
- end
88
-
89
- #Prints the results to standard out in the csv format specified.
90
- def display_results_csv
91
- puts "FileName,#{@folder1},#{@folder2},Are Equal"
92
- @filehash.each{ |key, value| puts "#{value.file_name},#{value.file_hash1},#{value.file_hash2}, #{value.file_hash1==value.file_hash2}" }
93
- end
94
-
95
- #Prints the results to standard out in the csv format specified.
96
- def display_results_html
97
- output ="<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title></title></head><body>"
98
- output.concat("<table><thead><tr><td>FileName</td></tr><tr><td>#{@folder1}</td></tr><tr><td>#{@folder2}</td></tr><tr><td>Equal</td></tr></thead>")
99
- @filehash.each{ |key, value| output.concat("<tbody><tr><td>#{value.file_name}</td></tr><tr><td>#{value.file_hash1}</td></tr><tr><td>#{value.file_hash2}</td></tr><tr><td>#{value.file_hash1==value.file_hash2}</td></tr>")}
100
- output.concat("</tbody></table></body></html>")
101
- puts output
102
- end
103
-
104
- #Prints the results to standard out in the csv format specified.
105
- def display_results_json
106
- puts @filehash
107
- end
108
-
109
- end
110
-
111
- #Container for the results of the file comparisson
112
- class FileHashResults
113
- attr_accessor :file_name, :file_hash1, :file_hash2
114
- def initialize(file_name, file_hash1, file_hash2)
115
- @file_name = file_name
116
- @file_hash1 = file_hash1
117
- @file_hash2 = file_hash2
118
- end
119
- end
120
- end
1
+ require 'digest/md5'
2
+
3
+ # Author:: John Ryan (mailto:555john@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 John Ryan
5
+ # License:: Distributes under the same terms as Ruby
6
+
7
+ module HashThatTree
8
+
9
+ # This class accepts two folders and provides methods to iterate
10
+ # through them creating a hash of each file within and can display
11
+ # the results for analysis
12
+ class CompareMD5
13
+ attr_accessor :folder1 #path to folder containing files to hash
14
+ attr_accessor :folder2 #path to folder containing files to hash to be compared to folder1
15
+ attr_accessor :format #the format to output the results to. csv, html or json
16
+
17
+ #initialize the class with the folders to be compared
18
+ def initialize(folder1, folder2, options)
19
+ @folder1 = folder1
20
+ @folder2 = folder2
21
+ @format = options['output']
22
+ @filehash = Hash.new
23
+ validate
24
+ end
25
+
26
+
27
+ # Validates the input ensuring the arguments are both valid folders
28
+ def validate
29
+ if(folder1==nil) || (folder1=="") || !Dir.exists?(folder1)
30
+ puts "a valid folder path is required as argument 1"
31
+ exit
32
+ end
33
+
34
+ if(folder2==nil) || (folder2=="") || !Dir.exists?(folder2)
35
+ puts "a valid folder path is required as argument 2"
36
+ exit
37
+ end
38
+
39
+ end
40
+
41
+ # Iterates through the folders and creates a FileHashResults object containing the
42
+ # results of the comparisson
43
+ def compare
44
+
45
+ Dir.foreach(@folder1) do |item|
46
+ begin
47
+ next if item == '.' or item == '..'
48
+ fullfilename = File.expand_path(@folder1, item)
49
+ the_hash = Digest::MD5.hexdigest(File.read(File.join(File.expand_path(@folder1), item)))
50
+ item = item.downcase
51
+ filedata = FileHashResults.new(item, the_hash, nil)
52
+ @filehash[item] = filedata
53
+ rescue
54
+ #puts "Skipped:#{item.inspect}"
55
+ end
56
+ end
57
+
58
+ Dir.foreach(@folder2) do |item|
59
+ begin
60
+ next if item == '.' or item == '..'
61
+ the_hash = Digest::MD5.hexdigest(File.read(File.join(@folder2, item)))
62
+ item = item.downcase
63
+ if(@filehash[item]==nil)
64
+ filedata = FileHashResults.new(item, nil, the_hash)
65
+ @filehash[item] = filedata
66
+ next
67
+ end
68
+ @filehash[item.downcase].file_hash2 = the_hash
69
+ rescue
70
+ #puts "Skipped:#{item.inspect}"
71
+ end
72
+ end
73
+ end
74
+
75
+ #print the contents of the FileHashResults object standard out in the format specified. Default is csv
76
+ def display_results()
77
+ case @format
78
+ when "csv"
79
+ display_results_csv
80
+ when "html"
81
+ display_results_html
82
+ when "json"
83
+ display_results_json
84
+ else
85
+ display_results_csv
86
+ end
87
+ end
88
+
89
+ #Prints the results to standard out in the csv format specified.
90
+ def display_results_csv
91
+ puts "FileName,#{@folder1},#{@folder2},Are Equal"
92
+ @filehash.each{ |key, value| puts "#{value.file_name},#{value.file_hash1},#{value.file_hash2}, #{value.file_hash1==value.file_hash2}" }
93
+ end
94
+
95
+ #Prints the results to standard out in the csv format specified.
96
+ def display_results_html
97
+ output ="<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title></title></head><body>"
98
+ output.concat("<table><thead><tr><td>FileName</td></tr><tr><td>#{@folder1}</td></tr><tr><td>#{@folder2}</td></tr><tr><td>Equal</td></tr></thead>")
99
+ @filehash.each{ |key, value| output.concat("<tbody><tr><td>#{value.file_name}</td></tr><tr><td>#{value.file_hash1}</td></tr><tr><td>#{value.file_hash2}</td></tr><tr><td>#{value.file_hash1==value.file_hash2}</td></tr>")}
100
+ output.concat("</tbody></table></body></html>")
101
+ puts output
102
+ end
103
+
104
+ #Prints the results to standard out in the csv format specified.
105
+ def display_results_json
106
+ puts @filehash
107
+ end
108
+
109
+ end
110
+
111
+ #Container for the results of the file comparisson
112
+ class FileHashResults
113
+ attr_accessor :file_name, :file_hash1, :file_hash2
114
+ def initialize(file_name, file_hash1, file_hash2)
115
+ @file_name = file_name
116
+ @file_hash1 = file_hash1
117
+ @file_hash2 = file_hash2
118
+ end
119
+ end
120
+ end