Class: ChupaText::Decomposers::Tar

Inherits:
ChupaText::Decomposer show all
Defined in:
lib/chupa-text/decomposers/tar.rb

Defined Under Namespace

Modules: CopyStreamable

Instance Method Summary collapse

Methods inherited from ChupaText::Decomposer

#initialize, registry, #target_score

Constructor Details

This class inherits a constructor from ChupaText::Decomposer

Instance Method Details

#decompose(data) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/chupa-text/decomposers/tar.rb', line 31

def decompose(data)
  data.open do |input|
    Gem::Package::TarReader.new(input) do |reader|
      reader.each do |entry|
        next unless entry.file?

        entry.extend(CopyStreamable)
        entry_uri = data.uri.dup
        base_path = entry_uri.path.gsub(/\.tar\z/i, "")
        path_converter = PathConverter.new(entry.full_name,
                                           uri_escape: true)
        entry_uri.path = "#{base_path}/#{path_converter.convert}"
        entry_data = VirtualFileData.new(entry_uri,
                                         entry,
                                         :source_data => data)
        yield(entry_data)
      end
    end
  end
end

#target?(data) ⇒ Boolean

Returns:

  • (Boolean)

26
27
28
29
# File 'lib/chupa-text/decomposers/tar.rb', line 26

def target?(data)
  data.extension == "tar" or
    data.mime_type == "application/x-tar"
end