Class: ChupaText::Decomposers::OfficeOpenXML

Inherits:
ChupaText::Decomposer show all
Includes:
Loggable, Unzippable
Defined in:
lib/chupa-text/decomposers/office-open-xml.rb

Defined Under Namespace

Classes: AttributesListener, TextListener

Instance Method Summary collapse

Methods inherited from ChupaText::Decomposer

#initialize, registry

Constructor Details

This class inherits a constructor from ChupaText::Decomposer

Instance Method Details

#decompose(data, &block) ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/chupa-text/decomposers/office-open-xml.rb', line 38

def decompose(data, &block)
  unzip(data) do |zip|
    context = {
      data: data,
      attributes: {},
    }
    start_decompose(context)
    zip.each do |entry|
      next unless entry.file?
      case entry.zip_path
      when "docProps/app.xml"
        listener = AttributesListener.new(context[:attributes])
        parse(entry.file_data, listener)
      when "docProps/core.xml"
        listener = AttributesListener.new(context[:attributes])
        parse(entry.file_data, listener)
      else
        process_entry(entry, context)
      end
    end
    finish_decompose(context, &block)
  end
end

#target?(data) ⇒ Boolean

Returns:

  • (Boolean)

25
26
27
28
# File 'lib/chupa-text/decomposers/office-open-xml.rb', line 25

def target?(data)
  @extensions.include?(data.extension) or
    @mime_types.include?(data.mime_type)
end

#target_score(data) ⇒ Object


30
31
32
33
34
35
36
# File 'lib/chupa-text/decomposers/office-open-xml.rb', line 30

def target_score(data)
  if target?(data)
    -1
  else
    nil
  end
end