Class: DoiExtractor::DownloadLocation

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_path, extract_group) ⇒ DownloadLocation

Returns a new instance of DownloadLocation.



6
7
8
9
10
11
12
13
# File 'lib/doi_extractor/download_location.rb', line 6

def initialize(base_path, extract_group)
  @extract_group = extract_group
  @base_path = base_path
  if extract_group.nil? || extract_group.year.nil? || extract_group.doi_version.nil?
    raise 'Cannot calculate path: missing doi extract data'
  end
  @path = File.join(base_path, "#{extract_group.year}_v#{extract_group.doi_version}")
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/doi_extractor/download_location.rb', line 4

def path
  @path
end

Instance Method Details

#clean_tmp!(er = nil) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/doi_extractor/download_location.rb', line 34

def clean_tmp!(er = nil)
  remove_tmp

  FileUtils.mkdir_p tmp_path
  if er
    FileUtils.mkdir_p extract_request_tmp_path(er)
  end
end

#complete_ddi_pathObject



47
48
49
# File 'lib/doi_extractor/download_location.rb', line 47

def complete_ddi_path
  File.join(ddi_path, 'complete.xml')
end

#complete_extract_request?(er) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
70
# File 'lib/doi_extractor/download_location.rb', line 67

def complete_extract_request?(er)
  file = extract_request_path(er)
  File.exist?(file)
end

#ddi_pathObject



51
52
53
# File 'lib/doi_extractor/download_location.rb', line 51

def ddi_path
  File.join(path, 'ddi')
end

#ensure!Object



19
20
21
22
# File 'lib/doi_extractor/download_location.rb', line 19

def ensure!
  FileUtils.mkdir_p path
  FileUtils.mkdir_p ddi_path
end

#exist?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/doi_extractor/download_location.rb', line 15

def exist?
  Dir.exist? path
end

#extract_request_filename(er) ⇒ Object



76
77
78
# File 'lib/doi_extractor/download_location.rb', line 76

def extract_request_filename(er)
  "#{extract_request_name(er)}.tar.gz"
end

#extract_request_name(er) ⇒ Object



80
81
82
83
# File 'lib/doi_extractor/download_location.rb', line 80

def extract_request_name(er)
  s = er.samples.first
  [s.name, s.long_description].compact.join(' - ').gsub('/', '_')
end

#extract_request_path(er) ⇒ Object



72
73
74
# File 'lib/doi_extractor/download_location.rb', line 72

def extract_request_path(er)
  File.join(path, extract_request_filename(er))
end

#extract_request_tmp_path(er) ⇒ Object



62
63
64
# File 'lib/doi_extractor/download_location.rb', line 62

def extract_request_tmp_path(er)
  File.join(tmp_path, extract_request_name(er))
end

#package_tmp_to_extract(er) ⇒ Object



55
56
57
58
59
60
# File 'lib/doi_extractor/download_location.rb', line 55

def package_tmp_to_extract(er)
  cmd = %[tar -czvf "#{extract_request_path(er)}" -C "#{tmp_path}" "#{extract_request_name(er)}"]
  output = `#{cmd} 2>&1`
  raise "error running command: #{cmd}\n#{output}" unless $?.success?
  output
end

#remove_tmpObject



28
29
30
31
32
# File 'lib/doi_extractor/download_location.rb', line 28

def remove_tmp
  if Dir.exist?(tmp_path)
    FileUtils.rm_rf tmp_path
  end
end

#summary_file_pathObject



43
44
45
# File 'lib/doi_extractor/download_location.rb', line 43

def summary_file_path
  File.join(path, 'summary.txt')
end

#tmp_pathObject



24
25
26
# File 'lib/doi_extractor/download_location.rb', line 24

def tmp_path
  File.join(path, 'tmp')
end