Class: AppleEpf::Extractor
- Inherits:
-
Object
- Object
- AppleEpf::Extractor
- Defined in:
- lib/apple_epf/extractor.rb
Defined Under Namespace
Classes: FileEntry
Instance Attribute Summary collapse
-
#basename ⇒ Object
readonly
Returns the value of attribute basename.
-
#dirname ⇒ Object
readonly
Returns the value of attribute dirname.
-
#file_entry ⇒ Object
readonly
Returns the value of attribute file_entry.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#keep_tbz_after_extract ⇒ Object
Returns the value of attribute keep_tbz_after_extract.
Instance Method Summary collapse
-
#initialize(filename, files_to_extract) ⇒ Extractor
constructor
A new instance of Extractor.
-
#perform ⇒ Object
TODO use multithread uncompressing tool.
Constructor Details
#initialize(filename, files_to_extract) ⇒ Extractor
Returns a new instance of Extractor.
8 9 10 11 12 13 14 |
# File 'lib/apple_epf/extractor.rb', line 8 def initialize(filename, files_to_extract) @filename = filename @files_to_extract = files_to_extract @dirname = File.dirname(@filename) @basename = File.basename(@filename) end |
Instance Attribute Details
#basename ⇒ Object (readonly)
Returns the value of attribute basename.
5 6 7 |
# File 'lib/apple_epf/extractor.rb', line 5 def basename @basename end |
#dirname ⇒ Object (readonly)
Returns the value of attribute dirname.
5 6 7 |
# File 'lib/apple_epf/extractor.rb', line 5 def dirname @dirname end |
#file_entry ⇒ Object (readonly)
Returns the value of attribute file_entry.
5 6 7 |
# File 'lib/apple_epf/extractor.rb', line 5 def file_entry @file_entry end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
5 6 7 |
# File 'lib/apple_epf/extractor.rb', line 5 def filename @filename end |
#keep_tbz_after_extract ⇒ Object
Returns the value of attribute keep_tbz_after_extract.
6 7 8 |
# File 'lib/apple_epf/extractor.rb', line 6 def keep_tbz_after_extract @keep_tbz_after_extract end |
Instance Method Details
#perform ⇒ Object
TODO use multithread uncompressing tool
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/apple_epf/extractor.rb', line 17 def perform @extracted_files = Array.new @files_to_extract.each do |f| @extracted_files.push File.basename(@filename, '.tbz') + '/' + f end result = system "cd #{@dirname} && tar -xjf #{@basename} #{@extracted_files.join(' ')}" if result _extracted_files = @extracted_files.map{|f| File.join(@dirname, f)} @file_entry = FileEntry.new(@filename, Hash[@files_to_extract.zip(_extracted_files)]) FileUtils.remove_file(@filename, true) unless keep_tbz_after_extract? else raise "Unable to extract files '#{@files_to_extract.join(' ')}' from #{@filename}" end @file_entry end |