Class: Cassiopee::CrawlerCache

Inherits:
Object
  • Object
show all
Defined in:
lib/cassiopee.rb

Overview

Class maning cache of results

Constant Summary collapse

FILE_CACHE_EXT =
".sfc"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCrawlerCache

Returns a new instance of CrawlerCache.



175
176
177
# File 'lib/cassiopee.rb', line 175

def initialize
			@file_suffix = "crawler"
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



166
167
168
# File 'lib/cassiopee.rb', line 166

def cache
  @cache
end

#errorsObject

max errors



164
165
166
# File 'lib/cassiopee.rb', line 164

def errors
  @errors
end

#file_suffixObject

Suffix files name/path



152
153
154
# File 'lib/cassiopee.rb', line 152

def file_suffix
  @file_suffix
end

#max_positionObject

Returns the value of attribute max_position.



161
162
163
# File 'lib/cassiopee.rb', line 161

def max_position
  @max_position
end

#methodObject

search exact: 0 hamming : 1 edit : 2



157
158
159
# File 'lib/cassiopee.rb', line 157

def method
  @method
end

#min_positionObject

filter



160
161
162
# File 'lib/cassiopee.rb', line 160

def min_position
  @min_position
end

Instance Method Details

#clearCacheObject



206
207
208
# File 'lib/cassiopee.rb', line 206

def clearCache
	File.delete(@file_suffix+FILE_CACHE_EXT) unless !File.exists?(@file_suffix+FILE_CACHE_EXT)
end

#loadCacheObject

Loads cache from file



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# 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

#saveCache(obj) ⇒ Object

Save self to cache, with cache object set from obj



197
198
199
200
201
202
203
204
# 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

#setLogger(userlogger) ⇒ Object



171
172
173
# File 'lib/cassiopee.rb', line 171

def setLogger(userlogger)
	$log = userlogger
end