Module: Omnizip::Profile
- Defined in:
- lib/omnizip/profile.rb,
lib/omnizip/profile/fast_profile.rb,
lib/omnizip/profile/text_profile.rb,
lib/omnizip/profile/binary_profile.rb,
lib/omnizip/profile/custom_profile.rb,
lib/omnizip/profile/archive_profile.rb,
lib/omnizip/profile/maximum_profile.rb,
lib/omnizip/profile/balanced_profile.rb,
lib/omnizip/profile/profile_detector.rb,
lib/omnizip/profile/profile_registry.rb,
lib/omnizip/profile/compression_profile.rb
Overview
Compression profile management
This module provides a high-level API for working with compression profiles. Profiles encapsulate compression settings and allow users to easily select optimal compression strategies for different file types.
Defined Under Namespace
Classes: ArchiveProfile, BalancedProfile, BinaryProfile, CompressionProfile, CustomProfile, FastProfile, MaximumProfile, ProfileDetector, ProfileRegistry, TextProfile
Class Method Summary collapse
-
.define(name, base: nil) {|builder| ... } ⇒ CustomProfile
Define a custom profile.
-
.detect(file_path, options = {}) ⇒ CompressionProfile
Auto-detect optimal profile for a file.
-
.detector ⇒ ProfileDetector
Get the profile detector.
-
.for_file_type(file_type) ⇒ CompressionProfile?
Get recommended profile for a file type.
-
.get(name) ⇒ CompressionProfile?
Get a profile by name.
-
.list ⇒ Array<Symbol>
List all available profile names.
-
.registry ⇒ ProfileRegistry
Get the global profile registry.
-
.reset! ⇒ void
Reset the global registry (mainly for testing).
Class Method Details
.define(name, base: nil) {|builder| ... } ⇒ CustomProfile
Define a custom profile
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/omnizip/profile.rb', line 62 def define(name, base: nil) base_profile = base ? registry.get(base) : nil builder = CustomProfile::Builder.new(name, base_profile) yield builder if block_given? builder.valid? profile = builder.build registry.register!(profile) profile end |
.detect(file_path, options = {}) ⇒ CompressionProfile
Auto-detect optimal profile for a file
107 108 109 |
# File 'lib/omnizip/profile.rb', line 107 def detect(file_path, = {}) detector.detect(file_path, ) end |
.detector ⇒ ProfileDetector
Get the profile detector
114 115 116 |
# File 'lib/omnizip/profile.rb', line 114 def detector @detector ||= ProfileDetector.new(registry) end |
.for_file_type(file_type) ⇒ CompressionProfile?
Get recommended profile for a file type
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/omnizip/profile.rb', line 86 def for_file_type(file_type) # If file_type is a symbol (category), find first suitable profile return find_profile_for_category(file_type) if file_type.is_a?(Symbol) # If file_type is a MIME string, find suitable profiles if file_type.is_a?(String) suitable = registry.suitable_for(file_type) return registry.get(:balanced) if suitable.empty? return select_best_profile_for_mime(suitable, file_type) end # Default to balanced registry.get(:balanced) end |
.get(name) ⇒ CompressionProfile?
Get a profile by name
36 37 38 |
# File 'lib/omnizip/profile.rb', line 36 def get(name) registry.get(name) end |
.list ⇒ Array<Symbol>
List all available profile names
78 79 80 |
# File 'lib/omnizip/profile.rb', line 78 def list registry.names end |
.registry ⇒ ProfileRegistry
Get the global profile registry
26 27 28 29 30 |
# File 'lib/omnizip/profile.rb', line 26 def registry @registry ||= ProfileRegistry.new.tap do |reg| register_built_in_profiles(reg) end end |
.reset! ⇒ void
This method returns an undefined value.
Reset the global registry (mainly for testing)
121 122 123 124 |
# File 'lib/omnizip/profile.rb', line 121 def reset! @registry = nil @detector = nil end |