module GeoElevation::Utils
Public Class Methods
get_common_string_start(urls)
click to toggle source
# File lib/utils.rb, line 7 def self.get_common_string_start(urls) if ! urls return nil end result = urls[0] for url in urls[1..-1] for i in 1..([result.length, url.length].max) if result[i] != url[i] break end end result = result[0..(i - 1)] end result end
ungzip(gzip_io, resulting_file_name)
click to toggle source
# File lib/utils.rb, line 37 def self.ungzip(gzip_io, resulting_file_name) puts "Ungzipping" result = Zlib::GzipReader.new(gzip_io).read puts "Saving" open(resulting_file_name, 'wb').write(result) nil end
unzip(zip_source, file_name)
click to toggle source
# File lib/utils.rb, line 24 def self.unzip(zip_source, file_name) temp_file = Tempfile::new(file_name) temp_file.write(zip_source) temp_file.rewind Zip::ZipFile.open(temp_file) do |zip_file| zip_file.each do |f| next unless "#{f}" == file_name return f.get_input_stream.read end end raise "No #{file_name} found in #{zip_source}" end