Class: Omnizip::Profile::CompressionProfile Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/profile/compression_profile.rb

Overview

This class is abstract.

Subclass and override #suitable_for? to implement a custom profile

Base class for compression profiles

A compression profile encapsulates a set of compression settings that define how files should be compressed. This includes the algorithm, compression level, filters, and other options.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initialize a new compression profile

Parameters:

  • name (Symbol)

    Profile name

  • algorithm (Symbol)

    Compression algorithm (:deflate, :lzma2, :ppmd7, etc.)

  • level (Integer)

    Compression level (0-9)

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

    Filter to apply (:bcj_x86, :bcj_arm, etc.)

  • solid (Boolean) (defaults to: false)

    Whether to use solid compression

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

    Human-readable description



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/omnizip/profile/compression_profile.rb', line 25

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

  validate!
  freeze
end

Instance Attribute Details

#algorithmObject (readonly)

Returns the value of attribute algorithm.



14
15
16
# File 'lib/omnizip/profile/compression_profile.rb', line 14

def algorithm
  @algorithm
end

#descriptionObject (readonly)

Returns the value of attribute description.



14
15
16
# File 'lib/omnizip/profile/compression_profile.rb', line 14

def description
  @description
end

#filterObject (readonly)

Returns the value of attribute filter.



14
15
16
# File 'lib/omnizip/profile/compression_profile.rb', line 14

def filter
  @filter
end

#levelObject (readonly)

Returns the value of attribute level.



14
15
16
# File 'lib/omnizip/profile/compression_profile.rb', line 14

def level
  @level
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/omnizip/profile/compression_profile.rb', line 14

def name
  @name
end

#solidObject (readonly)

Returns the value of attribute solid.



14
15
16
# File 'lib/omnizip/profile/compression_profile.rb', line 14

def solid
  @solid
end

Instance Method Details

#apply_to(options) ⇒ Hash

Apply this profile to compression options

Parameters:

  • options (Hash)

    Existing compression options

Returns:

  • (Hash)

    Updated compression options



48
49
50
51
52
53
54
55
56
57
# File 'lib/omnizip/profile/compression_profile.rb', line 48

def apply_to(options)
  options = options.dup

  options[:algorithm] = algorithm
  options[:level] = level
  options[:filter] = resolve_filter(options[:file_type]) if filter
  options[:solid] = solid

  options
end

#inspectString

Inspect representation

Returns:

  • (String)


92
93
94
95
# File 'lib/omnizip/profile/compression_profile.rb', line 92

def inspect
  "#<#{self.class.name} name=#{name} " \
    "algorithm=#{algorithm} level=#{level}>"
end

#suitable_for?(_mime_type) ⇒ Boolean

Check if this profile is suitable for a given MIME type

Parameters:

  • mime_type (String)

    MIME type string to check

Returns:

  • (Boolean)

    true if this profile is suitable



63
64
65
66
# File 'lib/omnizip/profile/compression_profile.rb', line 63

def suitable_for?(_mime_type)
  # Default implementation - subclasses should override
  true
end

#to_hHash

Get profile information as a hash

Returns:

  • (Hash)

    Profile properties



71
72
73
74
75
76
77
78
79
80
# File 'lib/omnizip/profile/compression_profile.rb', line 71

def to_h
  {
    name: name,
    algorithm: algorithm,
    level: level,
    filter: filter,
    solid: solid,
    description: description,
  }
end

#to_sString

String representation of the profile

Returns:

  • (String)


85
86
87
# File 'lib/omnizip/profile/compression_profile.rb', line 85

def to_s
  "#{name} - #{description}"
end