Class: Datasets::ZipExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/datasets/zip-extractor.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ZipExtractor

Returns a new instance of ZipExtractor.



5
6
7
# File 'lib/datasets/zip-extractor.rb', line 5

def initialize(path)
  @path = path
end

Instance Method Details

#extract_file(file_path) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/datasets/zip-extractor.rb', line 22

def extract_file(file_path)
  Zip::File.open(@path) do |zip_file|
    zip_file.each do |entry|
      next unless entry.file?
      next unless entry.name == file_path

      entry.get_input_stream do |input|
        return yield(input)
      end
    end
  end
  nil
end

#extract_filesObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/datasets/zip-extractor.rb', line 36

def extract_files
  Zip::File.open(@path) do |zip_file|
    zip_file.each do |entry|
      next unless entry.file?

      entry.get_input_stream do |input|
        yield(input)
      end
    end
  end
end

#extract_first_fileObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/datasets/zip-extractor.rb', line 9

def extract_first_file
  Zip::File.open(@path) do |zip_file|
    zip_file.each do |entry|
      next unless entry.file?

      entry.get_input_stream do |input|
        return yield(input)
      end
    end
  end
  nil
end