Class: Chimps::Commands::Download
- Inherits:
-
Chimps::Command
- Object
- OptionParser
- Chimps::Command
- Chimps::Commands::Download
- Defined in:
- lib/chimps/commands/download.rb
Overview
A command to download data from Infochimps.
Constant Summary collapse
- BANNER =
"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
-
#fmt ⇒ Object
The chosen data format.
-
#local_path ⇒ Object
readonly
The local path to download the data to.
-
#pkg_fmt ⇒ Object
The chosen package format.
Attributes inherited from Chimps::Command
Instance Method Summary collapse
-
#dataset ⇒ Object
The ID of the package to download.
- #define_options ⇒ Object
-
#execute! ⇒ Object
Issue the request for the token and the request for the download.
Methods inherited from Chimps::Command
Constructor Details
This class inherits a constructor from Chimps::Command
Instance Attribute Details
#fmt ⇒ Object
The chosen data format.
18 19 20 |
# File 'lib/chimps/commands/download.rb', line 18 def fmt @fmt end |
#local_path ⇒ Object (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_fmt ⇒ Object
The chosen package format.
21 22 23 |
# File 'lib/chimps/commands/download.rb', line 21 def pkg_fmt @pkg_fmt end |
Instance Method Details
#dataset ⇒ Object
The ID of the package to download.
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_options ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/chimps/commands/download.rb', line 58 def on_tail("-o", "--output PATH", "Path to download file to") do |o| @local_path = File.(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 |