class Giver require 'find' # get_filename_part returns an array of the $1 portion # of the match between filenames # under root_path and the regular expression frx, sorted by # frequency of occurrence def get_filename_part(public_path,frx) char_freq={} #possible_chars and their frequency of # occurrence in picture file_names char_freq.default=0 out_array=[] begin Find.find(File.join(Dir.pwd,'public', public_path)) do|path| # if FileTest.directory?(path) and if (File.basename(path)[0] == ?.) Find.prune # Don't look any further into #this directory. elsif !FileTest.directory?(path) && path.match(frx) found=$1 # p "found #{found}/#{path}" char_freq[found.upcase]+=1 if char_freq[found.upcase]==1 out_array << found #n!cdew item, disregarding case end #so that we # preserve case for file names end end rescue Exception out_array= ["error in getting files #{$!}"] end out_array.sort{|b,a| char_freq[a]<=>char_freq[b]} end #get_subdirs returns array of subdirectories under # "public" that do not # begin with a period def get_subdirs(root_dir) c=Dir.entries(File.join(Dir.pwd,'public',root_dir)) #don't want items containing . c.reject!{|d| d=~/\./} c end end