Sha256: 98354a28ebb7f5a5ee0dcdaba0dfa0953feccb3cae8ec979e7dfb8e7b96550ae
Contents?: true
Size: 1.21 KB
Versions: 3
Compression:
Stored size: 1.21 KB
Contents
require "zip" require "pathname" module Fontist module Utils module ZipExtractor # fonts_sub_dir is unused now, but formulas have this option # rubocop:disable Lint/UnusedMethodArgument def zip_extract(resource, download: true, fonts_sub_dir: "") zip_file = download_file(resource) if download zip_file ||= resource.urls.first fonts_paths = unzip_fonts(zip_file) block_given? ? yield(fonts_paths) : fonts_paths end # rubocop:enable Lint/UnusedMethodArgument alias_method :unzip, :zip_extract private # rubocop:disable Metrics/MethodLength, Metrics/AbcSize def unzip_fonts(file) Zip.on_exists_proc = true Array.new.tap do |fonts| Zip::File.open(file) do |zip_file| zip_file.glob("**/*.{ttf,ttc,otf}").each do |entry| if entry.name filename = Pathname.new(entry.name).basename font_path = fonts_path.join(filename.to_s) fonts.push(font_path.to_s) entry.extract(font_path) end end end end end # rubocop:enable Metrics/MethodLength, Metrics/AbcSize end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
fontist-1.5.1 | lib/fontist/utils/zip_extractor.rb |
fontist-1.5.0 | lib/fontist/utils/zip_extractor.rb |
fontist-1.4.0 | lib/fontist/utils/zip_extractor.rb |