class Cache

Public Class Methods

new() click to toggle source
# File lib/cache/cache.rb, line 2
def initialize
  @cache = {}
  @file = File.open('cache.dat', 'a+')
  read_cache
end

Public Instance Methods

add(word, thes, result) click to toggle source
# File lib/cache/cache.rb, line 8
def add(word, thes, result)
  word = word+"_thes" if thes
  @cache[word.to_sym] = result

  result = result.gsub(/\n+/,'@')
  @file.write "#{word}|| #{result}"
  @file.puts
end
read_cache() click to toggle source
# File lib/cache/cache.rb, line 22
def read_cache
  arr = IO.readlines("cache.dat")
  if arr 
    arr.each do |line|
      key, value = line.split('||')
      str = ''
      value = value.split('@')
      @cache[key.to_sym] = value
    end
  end
end