Class: DoiExtractor::DownloadLocation
- Inherits:
-
Object
- Object
- DoiExtractor::DownloadLocation
- Defined in:
- lib/doi_extractor/download_location.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #clean_tmp!(er = nil) ⇒ Object
- #complete_ddi_path ⇒ Object
- #complete_extract_request?(er) ⇒ Boolean
- #ddi_path ⇒ Object
- #ensure! ⇒ Object
- #exist? ⇒ Boolean
- #extract_request_filename(er) ⇒ Object
- #extract_request_name(er) ⇒ Object
- #extract_request_path(er) ⇒ Object
- #extract_request_tmp_path(er) ⇒ Object
-
#initialize(base_path, extract_group) ⇒ DownloadLocation
constructor
A new instance of DownloadLocation.
- #package_tmp_to_extract(er) ⇒ Object
- #remove_tmp ⇒ Object
- #summary_file_path ⇒ Object
- #tmp_path ⇒ Object
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
#path ⇒ Object (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_path ⇒ Object
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
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_path ⇒ Object
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
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_tmp ⇒ Object
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_path ⇒ Object
43 44 45 |
# File 'lib/doi_extractor/download_location.rb', line 43 def summary_file_path File.join(path, 'summary.txt') end |
#tmp_path ⇒ Object
24 25 26 |
# File 'lib/doi_extractor/download_location.rb', line 24 def tmp_path File.join(path, 'tmp') end |