Class: Chimps::Commands::Download

Inherits:
Chimps::Command show all
Defined in:
lib/chimps/commands/download.rb

Overview

A command to download data from Infochimps.

Constant Summary collapse

"usage: chimps download [OPTIONS] ID_OR_HANDLE"
HELP =
"\nDownload a dataset identified by the given ID_OR_HANDLE to the current\ndirectory (you can also specify a particular path).\n\nIf the dataset isn't freely downloadable, you'll have to have\npurchased it first via the Web.\n"

Instance Attribute Summary collapse

Attributes inherited from Chimps::Command

#argv

Instance Method Summary collapse

Methods inherited from Chimps::Command

#initialize, name, #name

Constructor Details

This class inherits a constructor from Chimps::Command

Instance Attribute Details

#fmtObject

The chosen data format.



18
19
20
# File 'lib/chimps/commands/download.rb', line 18

def fmt
  @fmt
end

#local_pathObject (readonly)

The local path to download the data to.



24
25
26
# File 'lib/chimps/commands/download.rb', line 24

def local_path
  @local_path
end

#pkg_fmtObject

The chosen package format.



21
22
23
# File 'lib/chimps/commands/download.rb', line 21

def pkg_fmt
  @pkg_fmt
end

Instance Method Details

#datasetObject

The ID of the package to download.

Raises:



47
48
49
50
# File 'lib/chimps/commands/download.rb', line 47

def dataset
  raise CLIError.new("Must provide an ID or handle of a dataset to download.") if argv.first.blank?
  argv.first
end

#define_optionsObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/chimps/commands/download.rb', line 58

def define_options
  on_tail("-o", "--output PATH", "Path to download file to") do |o|
    @local_path = File.expand_path(o)
  end

  on_tail("-f", "--format FORMAT", "Choose a particular data format (csv, tsv, excel, &c.)") do |f|
    self.fmt = f
  end

  on_tail("-p", "--package PACKAGE", "Choose a particular package type (zip or tar.bz2)") do |p|
    self.pkg_fmt = p
  end
  
end

#execute!Object

Issue the request for the token and the request for the download.



54
55
56
# File 'lib/chimps/commands/download.rb', line 54

def execute!
  Chimps::Workflows::Downloader.new(:dataset => dataset, :fmt => fmt, :pkg_fmt => pkg_fmt, :local_path => local_path).execute!
end