Module: Zipload

Defined in:
lib/zipload.rb,
lib/zipload/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.download_file(url) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/zipload.rb', line 17

def self.download_file(url)

    puts 'Downloading zipped file from url: ' + url

    fileNamePath = file_name_with_extension_from_url(url)
    uri = URI(url)
    zipped_folder = Net::HTTP.get(uri)

    File.open(fileNamePath, 'wb') do |file|
      file.write(zipped_folder)
    end

    Zip::File.open(fileNamePath) { |zip_file|
      zip_file.each { |file|
          file_path=File.join('output', file.name)
          FileUtils.mkdir_p(File.dirname(file_path))
          zip_file.extract(file, file_path) unless File.exist?(file_path)
        }
      }

end

.file_name_with_extension_from_url(url) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/zipload.rb', line 9

def self.file_name_with_extension_from_url(url)

    uri = URI.parse(url)
    fileNamePath = File.basename(uri.path)
    return fileNamePath

end