class NdrImport::File::Docx

This class is a modern Word document file handler that returns a single table. It only works on .docx documents

Private Instance Methods

decrypted_path() { |path| ... } click to toggle source

This method returns the path to the temporary, decrypted file

# File lib/ndr_import/file/docx.rb, line 34
def decrypted_path
  file_string = decrypted_file_string(@filename, @options['file_password'])
  Tempfile.create(['decrypted', '.docx'], encoding: file_string.encoding) do |file|
    file.write(file_string)
    file.close

    yield file.path
  end
end
rows() { |p| ... } click to toggle source
# File lib/ndr_import/file/docx.rb, line 17
def rows(&block)
  return enum_for(:rows) unless block

  send(@options['file_password'] ? :decrypted_path : :unencrypted_path) do |path|
    doc = ::Docx::Document.open(path)

    doc.paragraphs.each do |p|
      yield(p.to_s)
    end

    doc.zip.close
  end
rescue StandardError => e
  raise("#{SafeFile.basename(@filename)} [#{e.class}: #{e.message}]")
end
unencrypted_path() { |safepath_to_string| ... } click to toggle source

This method returns the safepath to the unencrypted docx file

# File lib/ndr_import/file/docx.rb, line 45
def unencrypted_path
  yield SafeFile.safepath_to_string(@filename)
end