Class: Cabriolet::OffsetCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/cabriolet/offset_calculator.rb

Overview

Abstract base class for offset calculators

Single responsibility: Calculate file positions within archive. Strategy pattern: Different formats implement different calculation strategies.

Subclasses must implement:

  • calculate(structure) - Returns hash of offsets

Examples:

Creating a calculator

class MyFormatCalculator < OffsetCalculator
  def calculate(structure)
    { header: 0, data: 100 }
  end
end

Direct Known Subclasses

CABOffsetCalculator

Instance Method Summary collapse

Instance Method Details

#calculate(structure) ⇒ Hash

Calculate all offsets in archive structure

Parameters:

  • structure (Hash)

    Archive structure with files, folders, etc.

Returns:

  • (Hash)

    Offset information

Raises:

  • (NotImplementedError)

    if not implemented by subclass



24
25
26
27
# File 'lib/cabriolet/offset_calculator.rb', line 24

def calculate(structure)
  raise NotImplementedError,
        "#{self.class.name} must implement calculate(structure)"
end