Class: Omnizip::Converter::ConversionRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/converter/conversion_registry.rb

Overview

Registry for conversion strategies

Class Method Summary collapse

Class Method Details

.find_strategy(source, target) ⇒ Class?

Find strategy for source and target formats

Parameters:

  • source (String)

    Source file path

  • target (String)

    Target file path

Returns:

  • (Class, nil)

    Strategy class or nil



20
21
22
# File 'lib/omnizip/converter/conversion_registry.rb', line 20

def find_strategy(source, target)
  @strategies.find { |strategy| strategy.can_convert?(source, target) }
end

.register(strategy_class) ⇒ Object

Register a conversion strategy

Parameters:

  • strategy_class (Class)

    Strategy class



12
13
14
# File 'lib/omnizip/converter/conversion_registry.rb', line 12

def register(strategy_class)
  @strategies << strategy_class unless @strategies.include?(strategy_class)
end

.resetObject

Reset registry (for testing)



39
40
41
# File 'lib/omnizip/converter/conversion_registry.rb', line 39

def reset
  @strategies = []
end

.strategiesArray<Class>

Get all registered strategies

Returns:

  • (Array<Class>)

    List of strategy classes



26
27
28
# File 'lib/omnizip/converter/conversion_registry.rb', line 26

def strategies
  @strategies
end

.supported?(source, target) ⇒ Boolean

Check if conversion is supported

Parameters:

  • source (String)

    Source file path

  • target (String)

    Target file path

Returns:

  • (Boolean)

    True if supported



34
35
36
# File 'lib/omnizip/converter/conversion_registry.rb', line 34

def supported?(source, target)
  !find_strategy(source, target).nil?
end