Class: Omnizip::Models::SplitOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/models/split_options.rb

Overview

Configuration for split archive (multi-volume) creation Defines how archives should be split into volumes

Constant Summary collapse

NAMING_NUMERIC =

Naming pattern types

:numeric
NAMING_ALPHA =

.001, .002, .003

:alpha
STRATEGY_FIRST_FIT =

Span strategies

:first_fit
STRATEGY_BALANCED =

Fill volumes sequentially

:balanced
DEFAULT_VOLUME_SIZE =

Default volume size (100 MB)

100 * 1024 * 1024

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSplitOptions

Initialize with default options



22
23
24
25
26
# File 'lib/omnizip/models/split_options.rb', line 22

def initialize
  @volume_size = DEFAULT_VOLUME_SIZE
  @naming_pattern = NAMING_NUMERIC
  @span_strategy = STRATEGY_FIRST_FIT
end

Instance Attribute Details

#naming_patternObject

Returns the value of attribute naming_pattern.



8
9
10
# File 'lib/omnizip/models/split_options.rb', line 8

def naming_pattern
  @naming_pattern
end

#span_strategyObject

Returns the value of attribute span_strategy.



8
9
10
# File 'lib/omnizip/models/split_options.rb', line 8

def span_strategy
  @span_strategy
end

#volume_sizeObject

Returns the value of attribute volume_size.



8
9
10
# File 'lib/omnizip/models/split_options.rb', line 8

def volume_size
  @volume_size
end

Class Method Details

.parse_volume_size(size_str) ⇒ Integer

Parse volume size from string (e.g., "100M", "4.7G")

Parameters:

  • size_str (String)

    Size string with unit

Returns:

  • (Integer)

    Size in bytes



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/omnizip/models/split_options.rb', line 32

def self.parse_volume_size(size_str)
  return size_str if size_str.is_a?(Integer)

  size_str = size_str.to_s.strip.upcase
  multiplier = case size_str
               when /(\d+(?:\.\d+)?)\s*K(?:B)?$/
                 1024
               when /(\d+(?:\.\d+)?)\s*M(?:B)?$/
                 1024 * 1024
               when /(\d+(?:\.\d+)?)\s*G(?:B)?$/
                 1024 * 1024 * 1024
               when /(\d+(?:\.\d+)?)\s*T(?:B)?$/
                 1024 * 1024 * 1024 * 1024
               else
                 return size_str.to_i
               end

  (Regexp.last_match(1).to_f * multiplier).to_i
end

Instance Method Details

#validate!Object

Validate options

Raises:

  • (ArgumentError)

    if options are invalid



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/omnizip/models/split_options.rb', line 75

def validate!
  raise ArgumentError, "volume_size must be positive" unless
    @volume_size.positive?

  valid_patterns = [NAMING_NUMERIC, NAMING_ALPHA]
  unless valid_patterns.include?(@naming_pattern)
    raise ArgumentError,
          "naming_pattern must be one of #{valid_patterns.inspect}"
  end

  valid_strategies = [STRATEGY_FIRST_FIT, STRATEGY_BALANCED]
  unless valid_strategies.include?(@span_strategy)
    raise ArgumentError,
          "span_strategy must be one of #{valid_strategies.inspect}"
  end

  true
end

#volume_filename(base_path, volume_number) ⇒ String

Generate volume filename

Parameters:

  • base_path (String)

    Base archive path (e.g., "backup.7z.001")

  • volume_number (Integer)

    Volume number (1-based)

Returns:

  • (String)

    Volume filename



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/omnizip/models/split_options.rb', line 57

def volume_filename(base_path, volume_number)
  # Extract base and extension
  base = base_path.sub(/\.\d{3}$/, "")
  base = base.sub(/\.[a-z]{2,}$/, "") if @naming_pattern == NAMING_ALPHA

  case @naming_pattern
  when NAMING_NUMERIC
    format("%s.%03d", base, volume_number)
  when NAMING_ALPHA
    format("%s.%s", base, alpha_suffix(volume_number))
  else
    format("%s.%03d", base, volume_number)
  end
end