-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
463 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module RDig | ||
module ContentExtractors | ||
|
||
# Extract text from word documents | ||
# | ||
# Requires the wvHtml utility | ||
# (on debian and friends do 'apt-get install wv') | ||
class WordContentExtractor < ContentExtractor | ||
include ExternalAppHelper | ||
|
||
def initialize(config) | ||
super(config) | ||
@wvhtml = 'wvHtml' | ||
@pattern = /^application\/msword/ | ||
# html extractor for parsing wvHtml output | ||
@html_extractor = RubyfulSoupContentExtractor.new(OpenStruct.new( | ||
:rubyful_soup => OpenStruct.new( | ||
:content_tag_selector => lambda { |tagsoup| | ||
tagsoup.html.body | ||
}, | ||
:title_tag_selector => lambda { |tagsoup| | ||
tagsoup.html.head.title | ||
} | ||
))) | ||
|
||
# TODO: better: if $?.exitstatus == 127 (not found) | ||
@available = %x{#{@wvhtml} -h 2>&1} =~ /Dom Lachowicz/ | ||
end | ||
|
||
def process(content) | ||
result = {} | ||
as_file(content) do |file| | ||
result = @html_extractor.process(%x{#{@wvhtml} --charset=UTF-8 '#{file.path}' -}) | ||
end | ||
return result || {} | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
Oops, something went wrong.