Class: Omnizip::Extraction::SelectiveExtractor
- Inherits:
-
Object
- Object
- Omnizip::Extraction::SelectiveExtractor
- Defined in:
- lib/omnizip/extraction/selective_extractor.rb
Overview
Coordinates selective extraction from archives
Extracts only files matching specified patterns, efficiently skipping non-matched files without decompression.
Instance Attribute Summary collapse
-
#archive ⇒ Object
readonly
Returns the value of attribute archive.
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
Instance Method Summary collapse
-
#count_matches ⇒ Integer
Count matching entries.
-
#extract(dest, options = {}) ⇒ Array<String>
Extract matching files to destination.
-
#extract_to_memory ⇒ Hash<String, String>
Extract matching files to memory.
-
#initialize(archive, filter = nil) ⇒ SelectiveExtractor
constructor
Initialize a new selective extractor.
-
#list_matches ⇒ Array
List matching entries without extracting.
-
#match_result ⇒ Models::MatchResult
Get match result with statistics.
Constructor Details
#initialize(archive, filter = nil) ⇒ SelectiveExtractor
Initialize a new selective extractor
18 19 20 21 |
# File 'lib/omnizip/extraction/selective_extractor.rb', line 18 def initialize(archive, filter = nil) @archive = archive @filter = normalize_filter(filter) end |
Instance Attribute Details
#archive ⇒ Object (readonly)
Returns the value of attribute archive.
12 13 14 |
# File 'lib/omnizip/extraction/selective_extractor.rb', line 12 def archive @archive end |
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
12 13 14 |
# File 'lib/omnizip/extraction/selective_extractor.rb', line 12 def filter @filter end |
Instance Method Details
#count_matches ⇒ Integer
Count matching entries
82 83 84 |
# File 'lib/omnizip/extraction/selective_extractor.rb', line 82 def count_matches list_matches.size end |
#extract(dest, options = {}) ⇒ Array<String>
Extract matching files to destination
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/omnizip/extraction/selective_extractor.rb', line 32 def extract(dest, = {}) FileUtils.mkdir_p(dest) extracted = [] entries_to_extract = list_matches total = entries_to_extract.size current = 0 entries_to_extract.each do |entry| dest_path = build_dest_path(entry, dest, ) extract_entry(entry, dest_path, ) extracted << dest_path # Update progress if tracker provided current += 1 update_progress([:progress], current, total, entry) end extracted end |
#extract_to_memory ⇒ Hash<String, String>
Extract matching files to memory
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/omnizip/extraction/selective_extractor.rb', line 56 def extract_to_memory result = {} list_matches.each do |entry| filename = entry_filename(entry) content = read_entry_content(entry) result[filename] = content end result end |
#list_matches ⇒ Array
List matching entries without extracting
71 72 73 74 75 76 77 |
# File 'lib/omnizip/extraction/selective_extractor.rb', line 71 def list_matches return list_all if @filter.nil? list_all.select do |entry| filter_matches?(entry) end end |
#match_result ⇒ Models::MatchResult
Get match result with statistics
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/omnizip/extraction/selective_extractor.rb', line 89 def match_result all_entries = list_all matches = if @filter all_entries.select { |entry| filter_matches?(entry) } else all_entries end Models::MatchResult.new( @filter&.to_s || "all", matches: matches, total_scanned: all_entries.size, ) end |