Skip to content

Instantly share code, notes, and snippets.

@lukeholder
Created November 9, 2012 08:00
Show Gist options
  • Save lukeholder/4044349 to your computer and use it in GitHub Desktop.
Save lukeholder/4044349 to your computer and use it in GitHub Desktop.
all files
def self.all
all_files = []
files = Dir.glob("#{INVOICES_PATH}/*")
files.sort.each do |file|
id = Digest::MD5.hexdigest(File.open(file, "rb") { |f| f.read })
file_obj = {
:id => id,
:name => File.basename(file),
:stamped => Stamp.exists?(:file_hash => id),
:dup => false
}
all_files << file_obj
end
all_files.group_by {|h| h[:id]}.each {|k,v| v.each_with_index {|o,i| o[:dup] = true if i > 0}}
#or to mark all as dup
# group_by {|h| h[key]}.each {|k,v| v.each{|o| o[dup_key]= true} if v.size > 1 }}
all_files.map { |f| new(f) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment