Class: Railsmdb::Extractor
- Inherits:
-
Object
- Object
- Railsmdb::Extractor
- Defined in:
- lib/railsmdb/extractor.rb
Overview
A utility class for extracting a specific file from a given archive. Currently only supports .tgz, .tar.gz, and .zip archives.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#archive_path ⇒ Object
readonly
The path to the archive.
Class Method Summary collapse
-
.for(archive_path) ⇒ ZipExtractor | TarGzipExtractor
Returns the appropriate extractor class for the given archive path.
Instance Method Summary collapse
-
#extract(pattern) {|String, String| ... } ⇒ String | nil
Extract the first file that matches the given pattern from the archive.
-
#initialize(archive_path) ⇒ Extractor
constructor
Instantiates a new extractor with the given archive path.
Constructor Details
#initialize(archive_path) ⇒ Extractor
Instantiates a new extractor with the given archive path.
31 32 33 |
# File 'lib/railsmdb/extractor.rb', line 31 def initialize(archive_path) @archive_path = archive_path end |
Instance Attribute Details
#archive_path ⇒ Object (readonly)
The path to the archive.
26 27 28 |
# File 'lib/railsmdb/extractor.rb', line 26 def archive_path @archive_path end |
Class Method Details
.for(archive_path) ⇒ ZipExtractor | TarGzipExtractor
Returns the appropriate extractor class for the given archive path.
17 18 19 20 21 22 23 |
# File 'lib/railsmdb/extractor.rb', line 17 def self.for(archive_path) case archive_path when /\.(tgz|tar\.gz)$/ then TarGzipExtractor.new(archive_path) when /\.zip$/ then ZipExtractor.new(archive_path) else raise ArgumentError, "don't know how to extract #{archive_path}" end end |
Instance Method Details
#extract(pattern) {|String, String| ... } ⇒ String | nil
Extract the first file that matches the given pattern from the archive.
47 48 49 |
# File 'lib/railsmdb/extractor.rb', line 47 def extract(pattern) raise NotImplementedError end |