Class: DFM

Inherits:
Object
  • Object
show all
Defined in:
lib/dfm.rb,
lib/dfm/version.rb

Overview

{ :filters => [“jpg”, “png”] } and path suh as { :path => “./” }

Constant Summary collapse

VERSION =

:nodoc:

"0.0.5"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ DFM

:nodoc:



15
16
17
18
19
20
21
22
# File 'lib/dfm.rb', line 15

def initialize( params = {} ) #:nodoc:
	@files_by_hexdigest = {}
	@files_by_name = {}
	@filters = Array( params.fetch( :filters, nil ) )
	@path = ( ( params.fetch( :path, '.' ) ) || '.' ) + File::SEPARATOR
	@hashFunc = Digest::MD5.new
	recurse_path( @path )
end

Instance Attribute Details

#filtersObject

File extension filters can be set on DFM.new( { :filters => [“jpg”,“gif”] } ) or you should assign it to the class instance variable filters before calling recurse( path )



13
14
15
# File 'lib/dfm.rb', line 13

def filters
  @filters
end

Instance Method Details

#hex(duplicates = true) ⇒ Object

Returns hash of duplicate files by MD5 hexdigest index. If the parameter is set to false then the hash returns non-duplicates.



40
41
42
# File 'lib/dfm.rb', line 40

def hex( duplicates = true )
	select_duplicates( { :hash => @files_by_hexdigest, :duplicates => duplicates } )
end

#name(duplicates = true) ⇒ Object

Returns hash of duplicate files by file name index. If the parameter is set to false then the hash returns non-duplicates.



46
47
48
# File 'lib/dfm.rb', line 46

def name( duplicates = true )
	select_duplicates( { :hash => @files_by_name, :duplicates => duplicates } )
end

Prints out JSON list of duplicate copy files by MD5 hexdigest index or if the parameter is set to “name” then the list is indexed by file name.



34
35
36
# File 'lib/dfm.rb', line 34

def print_duplicates( opt = "hex" )
	print_match( { :type => opt } )
end

Prints out JSON list of single copy files by MD5 hexdigest index or if the parameter is set to “name” then the list is indexed by file name.



27
28
29
# File 'lib/dfm.rb', line 27

def print_singles( opt = "hex" )
	print_match( { :type => opt, :duplicates => false } )
end

#recurse(path) ⇒ Object

Start a fresh recursive search with empty hash indexes. Accepts parameter for path. (See filters for setting file extensions.)



52
53
54
55
56
# File 'lib/dfm.rb', line 52

def recurse( path )
	@files_by_hexdigest = {}
	@files_by_name = {}
	recurse_path( path )
end