Class: Unarchiver
- Inherits:
-
Object
- Object
- Unarchiver
- Defined in:
- lib/unarchiver.rb,
lib/unarchiver/version.rb
Defined Under Namespace
Classes: ZipEntry
Constant Summary collapse
- VERSION =
"1.0.0"
Class Method Summary collapse
Instance Method Summary collapse
-
#expand(valid_extensions: nil) ⇒ Object
The dataset importer supports ZIP files which contain multiple underlying dataset files.
-
#initialize(file) ⇒ Unarchiver
constructor
A new instance of Unarchiver.
Constructor Details
#initialize(file) ⇒ Unarchiver
Returns a new instance of Unarchiver.
13 14 15 |
# File 'lib/unarchiver.rb', line 13 def initialize(file) @file = file end |
Class Method Details
.temp_file(contents, name, extension) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/unarchiver.rb', line 4 def self.temp_file(contents, name, extension) Tempfile.new([name, extension]).tap do |temp_file| temp_file.binmode temp_file.write(contents) temp_file.flush temp_file.rewind end end |
Instance Method Details
#expand(valid_extensions: nil) ⇒ Object
The dataset importer supports ZIP files which contain multiple underlying dataset files. This method will either return the original file if it is not a ZIP file, or will expand the ZIP file and return each of the potential dataset files included in it.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/unarchiver.rb', line 21 def (valid_extensions: nil) return [] unless file if (extension = File.extname(file.path)) == ".zip" (valid_extensions:) else # Ensure we're consistently returning an array of new tempfiles [self.class.temp_file(file.read, File.basename(file.path), extension)] end end |