Class: BiblioTech::Compression

Inherits:
Object
  • Object
show all
Defined in:
lib/bibliotech/compression.rb

Direct Known Subclasses

Bzip2, Gzip, SevenZip

Defined Under Namespace

Classes: Bzip2, Gzip, SevenZip

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(generator) ⇒ Compression

Returns a new instance of Compression.



26
27
28
# File 'lib/bibliotech/compression.rb', line 26

def initialize(generator)
  @generator = generator
end

Class Method Details

.for(filepath, generator) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/bibliotech/compression.rb', line 17

def for(filepath, generator)
  _, klass = @adapter_registry.find{ |pattern, klass|
    filepath =~ pattern
  }
  return generator if klass.nil?
  klass.new(generator)
end

.register(adapter_pattern, klass) ⇒ Object



5
6
7
# File 'lib/bibliotech/compression.rb', line 5

def register(adapter_pattern, klass)
  Compression.registry[adapter_pattern] = klass
end

.registryObject



9
10
11
# File 'lib/bibliotech/compression.rb', line 9

def registry
  @adapter_registry ||={}
end

.supported_adaptersObject



13
14
15
# File 'lib/bibliotech/compression.rb', line 13

def supported_adapters
  @adapter_registry.keys
end