8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/loader_ruby/loaders/docx.rb', line 8
def load(path, **opts)
check_file_exists!(path)
check_file_size!(path)
begin
require "docx"
rescue LoadError
raise DependencyMissingError,
"docx gem is required for DOCX loading. Add `gem 'docx'` to your Gemfile."
end
doc = ::Docx::Document.open(path)
paragraphs = doc.paragraphs.map(&:text)
content = paragraphs.join("\n")
Document.new(
content: content,
metadata: build_metadata(path,
format: :docx,
paragraphs: paragraphs.size
)
)
end
|