Module: SpatialFeatures::Unzip
- Defined in:
- lib/spatial_features/unzip.rb
Class Method Summary collapse
- .entries(file_path) ⇒ Object
- .is_zip?(file) ⇒ Boolean
- .names(file_path) ⇒ Object
- .paths(file_path, find: nil) ⇒ Object
Class Method Details
.entries(file_path) ⇒ Object
25 26 27 |
# File 'lib/spatial_features/unzip.rb', line 25 def self.entries(file_path) Zip::File.open(File.path(file_path)) end |
.is_zip?(file) ⇒ Boolean
29 30 31 32 33 34 35 |
# File 'lib/spatial_features/unzip.rb', line 29 def self.is_zip?(file) zip = file.readline.start_with?('PK') file.rewind return zip rescue EOFError return false end |
.names(file_path) ⇒ Object
21 22 23 |
# File 'lib/spatial_features/unzip.rb', line 21 def self.names(file_path) entries(file_path).collect(&:name) end |
.paths(file_path, find: nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/spatial_features/unzip.rb', line 3 def self.paths(file_path, find: nil) dir = Dir.mktmpdir paths = [] entries(file_path).each do |entry| path = "#{dir}/#{entry.name}" entry.extract(path) paths << path end if find = Array.wrap(find).presence paths = paths.detect {|path| find.any? {|pattern| path.include?(pattern) } } raise(ImportError, "No file matched #{find}") unless paths.present? end return paths end |