Class: ChupaText::Decomposers::Gzip

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

Constant Summary collapse

TARGET_EXTENSIONS =
["gz", "tgz"]
TARGET_MIME_TYPES =
[
  "application/gzip",
  "application/x-gzip",
  "application/x-gtar-compressed",
]

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



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/chupa-text/decomposers/gzip.rb', line 37

def decompose(data)
  open_reader(data) do |reader|
    uri = nil
    case data.extension
    when "gz"
    uri = data.uri.to_s.gsub(/\.gz\z/i, "")
    when "tgz"
      uri = data.uri.to_s.gsub(/\.tgz\z/i, ".tar")
    end
    extracted = VirtualFileData.new(uri, reader, :source_data => data)
    yield(extracted)
  end
end

#target?(data) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/chupa-text/decomposers/gzip.rb', line 32

def target?(data)
  TARGET_EXTENSIONS.include?(data.extension) or
    TARGET_MIME_TYPES.include?(data.mime_type)
end