class Datasets::Dataset

Attributes

metadata[R]

Public Class Methods

new() click to toggle source
# File lib/datasets/dataset.rb, line 13
def initialize
  @metadata = Metadata.new
end

Public Instance Methods

clear_cache!() click to toggle source
# File lib/datasets/dataset.rb, line 21
def clear_cache!
  if cache_dir_path.exist?
    FileUtils.rmtree(cache_dir_path.to_s, secure: true)
  end
end
to_table() click to toggle source
# File lib/datasets/dataset.rb, line 17
def to_table
  Table.new(self)
end

Private Instance Methods

cache_dir_path() click to toggle source
# File lib/datasets/dataset.rb, line 28
def cache_dir_path
  case RUBY_PLATFORM
  when /mswin/, /mingw/
    base_dir = ENV["LOCALAPPDATA"] || "~/AppData/Local"
  when /darwin/
    base_dir = "~/Library/Caches"
  else
    base_dir = ENV["XDG_CACHE_HOME"] || "~/.cache"
  end
  Pathname(base_dir).expand_path + "red-datasets" + metadata.id
end
download(output_path, url) click to toggle source
# File lib/datasets/dataset.rb, line 40
def download(output_path, url)
  downloader = Downloader.new(url)
  downloader.download(output_path)
end
extract_bz2(path) { |input| ... } click to toggle source
# File lib/datasets/dataset.rb, line 45
def extract_bz2(path)
  input, output = IO.pipe
  pid = spawn("bzcat", path.to_s, {:out => output})
  begin
    output.close
    yield(input)
  ensure
    input.close
    Process.waitpid(pid)
  end
end