Class: TF1Converter::KmzFile

Inherits:
Object
  • Object
show all
Defined in:
lib/tf1_converter/kmz_file.rb

Class Method Summary collapse

Class Method Details

.assemble!(filename) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tf1_converter/kmz_file.rb', line 6

def self.assemble!(filename)
  raw_name = filename.split(/[\/\\]/).last
  zip_path = "#{filename}.zip"
  FileUtils.rm(zip_path) if File.exists?(zip_path)
  Zip::ZipFile.open(zip_path, Zip::ZipFile::CREATE) do |zipfile|
    zipfile.add("#{raw_name}.kml", "#{filename}.kml")
    zipfile.mkdir("files")
    Dir.foreach(TF1Converter::Config.icon_path) do |item|
      if item != '.' && item != '..'
        zipfile.add("files/#{item}", "#{TF1Converter::Config.icon_path}/#{item}")
      end
    end
  end
  FileUtils.mv(zip_path, "#{filename}.kmz")
end