class MoocDataParser::DummyCacher

Public Class Methods

new() click to toggle source
# File lib/mooc_data_parser/dummy_cacher.rb, line 6
def initialize
  FileUtils.mkdir_p(path)
end

Public Instance Methods

cache_file(file) click to toggle source

Yep, well just overwrite it if it exists

# File lib/mooc_data_parser/dummy_cacher.rb, line 10
def cache_file(file)
  FileUtils.cp(file, path)
end
clean!() click to toggle source
# File lib/mooc_data_parser/dummy_cacher.rb, line 57
def clean!
  FileUtils.rm_rf path
end
file_exists?(file_name) click to toggle source
# File lib/mooc_data_parser/dummy_cacher.rb, line 30
def file_exists?(file_name)
  File.exists? get_from_cache(file_name)
end
find_files_matching(matcher) click to toggle source
# File lib/mooc_data_parser/dummy_cacher.rb, line 45
def find_files_matching(matcher)
  files = []
  Dir.chdir(path) do
    files = Dir.glob(matcher)
  end
  files
end
get_from_cache(file_name) click to toggle source
# File lib/mooc_data_parser/dummy_cacher.rb, line 26
def get_from_cache(file_name)
  File.join(path,  file_name)
end
path() click to toggle source
# File lib/mooc_data_parser/dummy_cacher.rb, line 53
def path
  File.join(tmpdir_path, "mooc-data-analyser")
end
read_file_from_cache(filename) click to toggle source
# File lib/mooc_data_parser/dummy_cacher.rb, line 20
def read_file_from_cache(filename)
  Dir.chdir(path) do
    File.read(filename)
  end
end
tmpdir_path() click to toggle source
# File lib/mooc_data_parser/dummy_cacher.rb, line 34
def tmpdir_path
  Dir.tmpdir
end
unzip_file(file_name) click to toggle source
# File lib/mooc_data_parser/dummy_cacher.rb, line 38
def unzip_file(file_name)
  Dir.chdir(path) do
    # Because I have found rubyzip to be buggy, we rely that your system has zip-command available
    `unzip -o  #{file_name}`
  end
end
write_file_to_cache(filename, contents) click to toggle source
# File lib/mooc_data_parser/dummy_cacher.rb, line 14
def write_file_to_cache(filename, contents)
  Dir.chdir(path) do
    File.open(filename, "wb") { |file| file.write(contents) }
  end
end