Module: SpatialFeatures::Download
- Defined in:
- lib/spatial_features/download.rb
Class Method Summary collapse
- .find_in_zip(file, unzip) ⇒ Object
- .normalize_file(file) ⇒ Object
- .open(file, unzip: nil) ⇒ Object
-
.read(file, unzip: nil) ⇒ Object
file can be a url, path, or file, any of which can return be a zipped archive.
Class Method Details
.find_in_zip(file, unzip) ⇒ Object
27 28 29 30 |
# File 'lib/spatial_features/download.rb', line 27 def self.find_in_zip(file, unzip) raise "Must specify an :unzip option if opening a zip file. e.g. open(file, :find => '.shp')" unless unzip return File.open(Unzip.paths(file, :find => unzip)) end |
.normalize_file(file) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/spatial_features/download.rb', line 19 def self.normalize_file(file) Tempfile.new.tap do |temp| temp.binmode temp.write(file.read) temp.rewind end end |
.open(file, unzip: nil) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/spatial_features/download.rb', line 12 def self.open(file, unzip: nil) file = Kernel.open(file) file = normalize_file(file) if file.is_a?(StringIO) file = find_in_zip(file, unzip) if Unzip.is_zip?(file) return file end |
.read(file, unzip: nil) ⇒ Object
file can be a url, path, or file, any of which can return be a zipped archive
6 7 8 9 10 |
# File 'lib/spatial_features/download.rb', line 6 def self.read(file, unzip: nil) file = open(file, unzip: unzip) path = ::File.path(file) return ::File.read(path) end |