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
16 17 18 19 |
# File 'lib/omnizip/extraction/selective_extractor.rb', line 16 def initialize(archive, filter = nil) @archive = archive @filter = normalize_filter(filter) end |
Instance Attribute Details
#archive ⇒ Object (readonly)
Returns the value of attribute archive.
10 11 12 |
# File 'lib/omnizip/extraction/selective_extractor.rb', line 10 def archive @archive end |
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
10 11 12 |
# File 'lib/omnizip/extraction/selective_extractor.rb', line 10 def filter @filter end |
Instance Method Details
#count_matches ⇒ Integer
Count matching entries
80 81 82 |
# File 'lib/omnizip/extraction/selective_extractor.rb', line 80 def count_matches list_matches.size end |
#extract(dest, options = {}) ⇒ Array<String>
Extract matching files to destination
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/omnizip/extraction/selective_extractor.rb', line 30 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
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/omnizip/extraction/selective_extractor.rb', line 54 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
69 70 71 72 73 74 75 |
# File 'lib/omnizip/extraction/selective_extractor.rb', line 69 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
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/omnizip/extraction/selective_extractor.rb', line 87 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 |