Class: Omnizip::Profile::CustomProfile

Inherits:
CompressionProfile show all
Defined in:
lib/omnizip/profile/custom_profile.rb

Overview

Custom user-defined compression profile

Allows users to create custom profiles with specific settings. Supports builder pattern for fluent API and profile inheritance.

Defined Under Namespace

Classes: Builder

Instance Attribute Summary collapse

Attributes inherited from CompressionProfile

#algorithm, #description, #filter, #level, #name, #solid

Instance Method Summary collapse

Methods inherited from CompressionProfile

#apply_to, #inspect, #to_s

Constructor Details

#initialize(name:, algorithm:, level:, filter: nil, solid: false, description: "", base_profile: nil) ⇒ CustomProfile

Initialize a custom profile

Parameters:

  • name (Symbol)

    Profile name

  • algorithm (Symbol)

    Compression algorithm

  • level (Integer)

    Compression level (0-9)

  • filter (Symbol, nil) (defaults to: nil)

    Filter to apply

  • solid (Boolean) (defaults to: false)

    Whether to use solid compression

  • description (String) (defaults to: "")

    Human-readable description

  • base_profile (CompressionProfile, nil) (defaults to: nil)

    Base profile extended



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/omnizip/profile/custom_profile.rb', line 114

def initialize(
  name:,
  algorithm:,
  level:,
  filter: nil,
  solid: false,
  description: "",
  base_profile: nil
)
  @base_profile = base_profile
  super(
    name: name,
    algorithm: algorithm,
    level: level,
    filter: filter,
    solid: solid,
    description: description
  )
end

Instance Attribute Details

#base_profileObject (readonly)

Returns the value of attribute base_profile.



103
104
105
# File 'lib/omnizip/profile/custom_profile.rb', line 103

def base_profile
  @base_profile
end

Instance Method Details

#suitable_for?(file_type) ⇒ Boolean

Check if this profile is suitable for a file type

Parameters:

  • file_type (Omnizip::FileType::DetectionResult)

    File type

Returns:

  • (Boolean)

    Delegates to base profile if available



138
139
140
141
142
143
# File 'lib/omnizip/profile/custom_profile.rb', line 138

def suitable_for?(file_type)
  return base_profile.suitable_for?(file_type) if base_profile

  # Custom profiles are suitable for all file types by default
  true
end

#to_hHash

Convert to hash with base profile information

Returns:

  • (Hash)

    Profile properties including base



148
149
150
151
152
# File 'lib/omnizip/profile/custom_profile.rb', line 148

def to_h
  hash = super
  hash[:base_profile] = base_profile.name if base_profile
  hash
end