Sha256: da70bdbbee202d503f369aa2010e96d2ee4ce2cb14beac816c8229a3c1cefdb9

Contents?: true

Size: 885 Bytes

Versions: 53

Compression:

Stored size: 885 Bytes

Contents

require 'msworddoc-extractor'
require 'ndr_support/safe_file'
require_relative 'registry'

module NdrImport
  # This is one of a collection of file handlers that deal with individual formats of data.
  # They can be instantiated directly or via the factory method Registry.tables
  module File
    # This class is a Word document file handler that returns a single table.
    # currently only works on .doc (97-2003), not.docx
    class Word < Base
      private

      def rows(&block)
        return enum_for(:rows) unless block

        doc = MSWordDoc::Extractor.load(SafeFile.safepath_to_string(@filename))

        doc.whole_contents.split("\n").each do |line|
          block.call(line)
        end

      rescue => e
        raise("#{SafeFile.basename(@filename)} [#{e.class}: #{e.message}]")
      end
    end

    Registry.register(Word, 'doc') # TODO: Add 'word'?
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
ndr_import-4.1.1 lib/ndr_import/file/word.rb
ndr_import-4.1.0 lib/ndr_import/file/word.rb
ndr_import-4.0.1 lib/ndr_import/file/word.rb
ndr_import-4.0.0 lib/ndr_import/file/word.rb
ndr_import-3.1.6 lib/ndr_import/file/word.rb
ndr_import-3.1.5 lib/ndr_import/file/word.rb
ndr_import-3.1.4 lib/ndr_import/file/word.rb
ndr_import-3.1.3 lib/ndr_import/file/word.rb
ndr_import-3.1.2 lib/ndr_import/file/word.rb
ndr_import-3.1.1 lib/ndr_import/file/word.rb
ndr_import-3.1.0 lib/ndr_import/file/word.rb
ndr_import-3.0.1 lib/ndr_import/file/word.rb
ndr_import-3.0.0 lib/ndr_import/file/word.rb