Class: Pandata::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/pandata/cli.rb

Overview

Pandata command-line interface

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ CLI

Returns a new instance of CLI.



24
25
26
27
28
29
30
31
# File 'lib/pandata/cli.rb', line 24

def initialize(options)
  @data_to_get = options[:data_to_get]
  @output_file = options[:output_file]
  @return_as_json = options[:return_as_json]

  @scraper = scraper_for(options[:user_id])
  @scraper.download_cb = method(:update_progress)
end

Class Method Details

.scrape(argv) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pandata/cli.rb', line 12

def self.scrape(argv)
  options = Pandata::ArgvParser.parse(argv)

  if argv.empty? || options[:help]
    puts options[:opts].to_s  # Log usage information
  elsif options[:version]
    puts Pandata::Version::STRING
  else
    new(options).download_and_output
  end
end

Instance Method Details

#download_and_outputObject



37
38
39
# File 'lib/pandata/cli.rb', line 37

def download_and_output
  output_data format_data(download_data, @return_as_json)
end

#update_progress(new_data) ⇒ Object



33
34
35
# File 'lib/pandata/cli.rb', line 33

def update_progress(new_data)
  progressbar.progress += new_data.size
end