Class: Nsrr::Commands::Download

Inherits:
Object
  • Object
show all
Defined in:
lib/nsrr/commands/download.rb

Overview

Downloads a folder or a file from the NSRR webserver. Folders can be downloaded recursively.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Download

Returns a new instance of Download.



20
21
22
23
24
25
26
27
# File 'lib/nsrr/commands/download.rb', line 20

def initialize(argv)
  (@token, argv) = parse_parameter_with_value(argv, ["token"], "")
  (@file_comparison, argv) = parse_parameter(argv, ["fast", "fresh", "md5"], "md5")
  (@depth, argv) = parse_parameter(argv, ["shallow", "recursive"], "recursive")
  (@file, argv) = parse_parameter_with_value(argv, ["file"], "")
  @dataset_slug = argv[1].to_s.split("/").first
  @full_path = (argv[1].to_s.split("/")[1..-1] || []).join("/")
end

Instance Attribute Details

#dataset_slugObject (readonly)

Returns the value of attribute dataset_slug.



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

def dataset_slug
  @dataset_slug
end

#depthObject (readonly)

Returns the value of attribute depth.



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

def depth
  @depth
end

#file_comparisonObject (readonly)

Returns the value of attribute file_comparison.



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

def file_comparison
  @file_comparison
end

#full_pathObject (readonly)

Returns the value of attribute full_path.



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

def full_path
  @full_path
end

#tokenObject (readonly)

Returns the value of attribute token.



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

def token
  @token
end

Class Method Details

.run(*args) ⇒ Object



13
14
15
# File 'lib/nsrr/commands/download.rb', line 13

def run(*args)
  new(*args).run
end

Instance Method Details

#runObject

Run with Authorization



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/nsrr/commands/download.rb', line 30

def run
  if @dataset_slug.nil?
    puts "Please specify a dataset: " + "nsrr download DATASET".white
    puts "Read more on the download command here:"
    puts "  " + "https://github.com/nsrr/nsrr-gem".bg_gray.blue.underline
  else
    @token = Nsrr::Helpers::Authorization.get_token(@token) if @token.to_s == ""
    @dataset = Dataset.find(@dataset_slug, @token)
    if @dataset
      @dataset.download(@full_path, depth: @depth, method: @file_comparison, file: Regexp.new(@file))
    else
      puts "\nThe dataset " + @dataset_slug.white + " was not found."
      datasets = all_datasets
      return if datasets.empty?

      puts "Did you mean one of: #{datasets.collect { |d| d["slug"].white }.sort.join(", ")}"
    end
  end
rescue Interrupt
  puts "\nINTERRUPTED".red
end