Class maning cache of results
max errors
Suffix files name/path
search exact: 0 hamming : 1 edit : 2
filter
# File lib/cassiopee.rb, line 175 def initialize @file_suffix = "crawler" end
# File lib/cassiopee.rb, line 206 def clearCache File.delete(@file_suffix+FILE_CACHE_EXT) unless !File.exists?(@file_suffix+FILE_CACHE_EXT) end
Loads cache from file
# File lib/cassiopee.rb, line 180 def loadCache return Array.new unless File.exists?(@file_suffix+FILE_CACHE_EXT) begin file = Zlib::GzipReader.open(@file_suffix+FILE_CACHE_EXT) rescue Zlib::GzipFile::Error file = File.open(@file_suffix+FILE_CACHE_EXT, 'r') ensure obj = Marshal.load file.read file.close if(method!=obj.method || min_position<obj.min_position || max_position>obj.max_position || errors>obj.errors) return Array.new end return filterCache(obj) end end
Save self to cache, with cache object set from obj
# File lib/cassiopee.rb, line 197 def saveCache(obj) self.cache = obj marshal_dump = Marshal.dump(self) sfxpos = File.new(@file_suffix+FILE_CACHE_EXT,'w') sfxpos = Zlib::GzipWriter.new(sfxpos) sfxpos.write marshal_dump sfxpos.close end
# File lib/cassiopee.rb, line 171 def setLogger(userlogger) $log = userlogger end
filter cache according to settings obj: cache object
# File lib/cassiopee.rb, line 214 def filterCache(cacheobject) realmatches = Array.new if(cacheobject==nil) return realmatches end cacheobject.cache.each do |obj| if(obj[1]>self.errors) next end realpos = Array.new realpos << obj[2][0] (1..obj[2].length-1).each do |i| curpos= obj[2][i] if((curpos<=max_position || max_position==0) && curpos>=min_position) realpos << curpos end end if(realpos.length<=1) next end realmatches << Array[obj[0],obj[1],realpos] end return realmatches end