class Opensaz::Extractor

Public Class Methods

new(saz_path) click to toggle source
# File lib/opensaz/extractor.rb, line 7
def initialize(saz_path)
  # saz_path should be absolute path
  raise "no such file: #{saz_path}" unless File.exist?(saz_path)
  @saz = saz_path
  @md5 = Digest::MD5.hexdigest(File.read(@saz))
end

Private Class Methods

unzip(file, destination) click to toggle source
# File lib/opensaz/extractor.rb, line 28
def self.unzip(file, destination)
  begin
    Zip::File.open(file) do |zip_file|
      zip_file.each do |f|
        fpath = File.join(destination, f.name)
        zip_file.extract(f, fpath) unless File.exist?(fpath)
      end
    end
  rescue Zip::Error => e
    raise e.message
  end
  destination
end

Public Instance Methods

unzip() click to toggle source
# File lib/opensaz/extractor.rb, line 14
def unzip
  File.exist?(destination) ? destination : Extractor.unzip(@saz, destination)
end

Private Instance Methods

destination() click to toggle source
# File lib/opensaz/extractor.rb, line 20
def destination
  File.join(Dir.pwd, filename)
end
filename() click to toggle source
# File lib/opensaz/extractor.rb, line 24
def filename
  File.basename(@saz, ".*") + "_" + @md5
end