Class: DoiExtractor::StatusCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/doi_extractor/status_command.rb

Instance Attribute Summary

Attributes inherited from Command

#log, #options, #start_time, #std_out, #user_input_callback

Instance Method Summary collapse

Methods inherited from Command

#execute, for, #initialize

Constructor Details

This class inherits a constructor from DoiExtractor::Command

Instance Method Details

#_executeObject



4
5
6
7
8
9
10
# File 'lib/doi_extractor/status_command.rb', line 4

def _execute
  if options.extract_group_id
    report_group(options.extract_group_id)
  else
    report_recent
  end
end

#report_group(id) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/doi_extractor/status_command.rb', line 12

def report_group(id)
  doi_extract = ipums_client.get_doi_extract(id)

  unless doi_extract
    fail("no extract for #{id} found")
  end

  location = DownloadLocation.new(options.download_base_path, doi_extract)

  say_doi_summary(doi_extract, location)
  say("Extract Requests:")

  fmt = '%-10s%25s%20s%12s'

  say(sprintf(fmt.sub('i', 's'), 'ID', 'Status', 'Sample', 'Downloaded'))
  doi_extract.extract_requests.each do |er|
    say(sprintf(fmt, er.id, er.completion_status, er.samples.first.name, location.complete_extract_request?(er)))
  end

end

#report_recentObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/doi_extractor/status_command.rb', line 33

def report_recent
  recent = ipums_client.recent_doi_extracts

  if recent.nil? || recent.empty?
    say("There are no DOI extracts")
  else
    recent.each do |doi|
      location = DownloadLocation.new(options.download_base_path, doi)
      say_doi_summary(doi, location)
      say("\tExtracts:       #{doi.extract_requests.count}")
    end
  end
end

#say_doi_summary(doi_extract, location) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/doi_extractor/status_command.rb', line 47

def say_doi_summary(doi_extract, location)
  count_hsh = Hash.new { |h, k| h[k] = 0 }
  extract_counts = doi_extract.extract_requests.reduce(count_hsh) { |h, e| h[e.completion_status] += 1; h }

  say("DOI Extract (ID: #{doi_extract.id})")
  say("\tStatus:         #{doi_extract.status}")
  say("\tCreated:        #{doi_extract.created_at}")
  say("\tSubmitted:      #{doi_extract.submit_date}")
  say("\tFinished:       #{doi_extract.finish_date}")
  say("\tData Available: #{doi_extract.all_data_available}")
  say("\tPath:           #{location.path}")
  say("\tExtract Counts: #{extract_counts.map { |k, v| "#{k}: #{v}" }.join(', ')}")
  say("\tDownloaded:     #{doi_extract.extract_requests.any? && doi_extract.extract_requests.all? { |er| location.complete_extract_request?(er) }}")
end