lib/fontist/import/recursive_extraction.rb in fontist-1.16.0 vs lib/fontist/import/recursive_extraction.rb in fontist-1.17.0

- old
+ new

@@ -6,13 +6,14 @@ module Import class RecursiveExtraction LICENSE_PATTERN = /(ofl\.txt|ufl\.txt|licenses?\.txt|license(\.md)?|copying)$/i.freeze - def initialize(archive, subarchive: nil, subdir: nil) + def initialize(archive, subdir: nil, file_pattern: nil) @archive = archive @subdir = subdir + @file_pattern = file_pattern @operations = {} @font_files = [] @collection_files = [] save_operation_subdir @@ -70,14 +71,15 @@ @extracted = true end def extract_data(archive) Excavate::Archive.new(path(archive)).files(recursive_packages: true) do |path| + Fontist.ui.debug(path) next unless File.file?(path) match_license(path) - match_font(path) if font_directory?(path) + match_font(path) if font_candidate?(path) end end def path(file) file.respond_to?(:path) ? file.path : file @@ -108,17 +110,27 @@ file.version == candidate.version && file.font == candidate.font end end + def font_candidate?(path) + font_directory?(path) && file_pattern?(path) + end + def font_directory?(path) return true unless subdirectory_pattern File.fnmatch?(subdirectory_pattern, File.dirname(path)) end def subdirectory_pattern @subdirectory_pattern ||= "*" + @subdir.chomp("/") if @subdir + end + + def file_pattern?(path) + return true unless @file_pattern + + File.fnmatch?(@file_pattern, File.basename(path)) end end end end