Sha256: 32ee9d6810c64135de5ed7a857bfd920287962bd5fb7f44cf1c5550201f92a91

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

require "pathname"

require_relative "downloader"
require_relative "metadata"
require_relative "table"

module Datasets
  class Dataset
    include Enumerable

    attr_reader :metadata
    def initialize
      @metadata = Metadata.new
    end

    def to_table
      Table.new(self)
    end

    private
    def cache_dir_path
      case RUBY_PLATFORM
      when /mswin/, /mingw/
        base_dir = ENV["LOCALAPPDATA"] || "~/AppData"
      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

    def download(output_path, url)
      downloader = Downloader.new(url)
      downloader.download(output_path)
    end

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
red-datasets-0.1.0 lib/datasets/dataset.rb
red-datasets-0.0.9 lib/datasets/dataset.rb