hash-that-tree 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
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
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+ .project
20
+ *~
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hash-that-tree.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hash-that-tree (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ x86-mingw32
12
+
13
+ DEPENDENCIES
14
+ hash-that-tree!
data/LICENSE.txt ADDED
@@ -0,0 +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
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ #hash-that-tree
2
+ a ruby app that compares the MD5 hashes of the files in two different folders
3
+
4
+ Looking into bundling with https://github.com/radar/guides/blob/master/gem-development.md
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'hash-that-tree'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install hash-that-tree
19
+
20
+ ## Usage
21
+
22
+ hashthattree.rb c:/testfiles/folder1 c:/testfiles/folder2
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "hash-that-tree"
8
+ gem.version = HashThatTree::VERSION
9
+ gem.authors = ["John Ryan"]
10
+ gem.email = ["johnryan_irl@yahoo.com"]
11
+ gem.description = "compares the MD5 hashes of the files in two different folders"
12
+ gem.summary = "Allows the user to enter two folder locations and the gem will iterate through the files, creating and comparing the MD5 hashes of the files with the same name"
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,64 @@
1
+ require 'digest/md5'
2
+
3
+ module HashThatTree
4
+ class HashThatTree
5
+ attr_accessor :folder1, :folder2
6
+
7
+ def initialize(folder1, folder2)
8
+ @folder1 = folder1
9
+ @folder2 = folder2
10
+ @filehash = Hash.new
11
+ usage
12
+ end
13
+ def usage
14
+ if(folder1==nil) || (folder1=="") || !Dir.exists?(folder1)
15
+ puts "a valid folder path is required as argument 1"
16
+ exit
17
+ end
18
+
19
+ if(folder2==nil) || (folder2=="") || !Dir.exists?(folder2)
20
+ puts "a valid folder path is required as argument 2"
21
+ exit
22
+ end
23
+
24
+ end
25
+
26
+ def compare_folders
27
+
28
+ Dir.foreach(@folder1) do |item|
29
+ next if item == '.' or item == '..'
30
+ the_hash = Digest::MD5.hexdigest(File.read(File.join(@folder1, item)))
31
+ filedata = FileData.new(the_hash, nil)
32
+ @filehash[item] = filedata
33
+ end
34
+
35
+ Dir.foreach(@folder2) do |item|
36
+ next if item == '.' or item == '..'
37
+ the_hash = Digest::MD5.hexdigest(File.read(File.join(@folder2, item)))
38
+ if(@filehash[item]==nil)
39
+ filedata = FileData.new(nil, the_hash)
40
+ @filehash[item] = filedata
41
+ next
42
+ end
43
+ @filehash[item].file2 = the_hash
44
+ end
45
+ end
46
+
47
+ def display_results
48
+ puts "FileName Hash1 Hash2"
49
+ @filehash.each{ |key, value| puts "#{key} is #{value.file1} #{value.file2}" }
50
+ end
51
+ end
52
+
53
+ class FileData
54
+ attr_accessor :file1, :file2
55
+ def initialize(file1, file2)
56
+ @file1 = file1
57
+ @file2 = file2
58
+ end
59
+ end
60
+
61
+ htt = HashThatTree.new(ARGV[0], ARGV[1])
62
+ htt.compare_folders
63
+ htt.display_results
64
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module HashThatTree
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hash-that-tree
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Ryan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-05 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: compares the MD5 hashes of the files in two different folders
15
+ email:
16
+ - johnryan_irl@yahoo.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - hash-that-tree.gemspec
28
+ - lib/hashthattree.rb
29
+ - lib/version.rb
30
+ homepage: ''
31
+ licenses: []
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 1.8.24
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: Allows the user to enter two folder locations and the gem will iterate through
54
+ the files, creating and comparing the MD5 hashes of the files with the same name
55
+ test_files: []