Module: Cabriolet::Auto
- Defined in:
- lib/cabriolet/auto.rb
Overview
Auto-detection and extraction module
Defined Under Namespace
Classes: SimpleExtractor
Class Method Summary collapse
-
.detect_format(path) ⇒ Symbol?
Detect format only without parsing.
-
.extract(archive_path, output_dir, **options) ⇒ Hash
Detect format and extract all files automatically.
-
.info(path) ⇒ Hash
Get information about an archive without full extraction.
-
.open(path, **options) ⇒ Object
Open and parse an archive with automatic format detection.
Class Method Details
.detect_format(path) ⇒ Symbol?
Detect format only without parsing
69 70 71 |
# File 'lib/cabriolet/auto.rb', line 69 def detect_format(path) FormatDetector.detect(path) end |
.extract(archive_path, output_dir, **options) ⇒ Hash
Detect format and extract all files automatically
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/cabriolet/auto.rb', line 49 def extract(archive_path, output_dir, **) archive = open(archive_path) extractor = if [:parallel] ParallelExtractor.new(archive, output_dir, **) else SimpleExtractor.new(archive, output_dir, **) end extractor.extract_all end |
.info(path) ⇒ Hash
Get information about an archive without full extraction
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/cabriolet/auto.rb', line 81 def info(path) archive = open(path) format = detect_format(path) { format: format, path: path, file_count: archive.files.count, total_size: archive.files.sum { |f| f.size || 0 }, compressed_size: File.size(path), compression_ratio: calculate_compression_ratio(archive, path), files: archive.files.map { |f| file_info(f) }, } end |
.open(path, **options) ⇒ Object
Open and parse an archive with automatic format detection
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cabriolet/auto.rb', line 19 def open(path, **) format = FormatDetector.detect(path) unless format raise UnsupportedFormatError, "Unable to detect format for: #{path}" end parser_class = FormatDetector.format_to_parser(format) unless parser_class raise UnsupportedFormatError, "No parser available for format: #{format}" end parser_class.new(**).parse(path) end |