Class: WordToMarkdown
- Inherits:
-
Object
- Object
- WordToMarkdown
- Defined in:
- lib/word-to-markdown.rb,
lib/word-to-markdown/version.rb,
lib/word-to-markdown/document.rb,
lib/word-to-markdown/converter.rb
Defined Under Namespace
Constant Summary collapse
- REVERSE_MARKDOWN_OPTIONS =
Options to be passed to Reverse Markdown
{ unknown_tags: :bypass, github_flavored: true }.freeze
- SOFFICE_VERSION_REQUIREMENT =
Minimum version of LibreOffice Required
'> 4.0'
- PATHS =
Paths to look for LibreOffice, in order of preference
[ '*', # Sub'd for ENV["PATH"] '~/Applications/LibreOffice.app/Contents/MacOS', '/Applications/LibreOffice.app/Contents/MacOS', '/Program Files/LibreOffice 5/program', '/Program Files (x86)/LibreOffice 4/program' ].freeze
- VERSION =
'1.1.9'
Instance Attribute Summary collapse
-
#converter ⇒ Object
readonly
Returns the value of attribute converter.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Class Method Summary collapse
-
.logger ⇒ Object
Logger instance.
-
.run_command(*args) ⇒ string
Run an soffice command.
-
.soffice ⇒ Object
Returns a Cliver::Dependency object representing our soffice dependency.
Instance Method Summary collapse
-
#initialize(path, tmpdir = nil) ⇒ WordToMarkdown
constructor
Create a new WordToMarkdown object.
-
#to_s ⇒ string
Helper method to return the document body, as markdown.
Constructor Details
#initialize(path, tmpdir = nil) ⇒ WordToMarkdown
Create a new WordToMarkdown object
46 47 48 49 50 |
# File 'lib/word-to-markdown.rb', line 46 def initialize(path, tmpdir = nil) @document = WordToMarkdown::Document.new path, tmpdir @converter = WordToMarkdown::Converter.new @document converter.convert! end |
Instance Attribute Details
#converter ⇒ Object (readonly)
Returns the value of attribute converter.
21 22 23 |
# File 'lib/word-to-markdown.rb', line 21 def converter @converter end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
21 22 23 |
# File 'lib/word-to-markdown.rb', line 21 def document @document end |
Class Method Details
.logger ⇒ Object
Returns Logger instance.
87 88 89 90 91 92 93 |
# File 'lib/word-to-markdown.rb', line 87 def logger @logger ||= begin logger = Logger.new($stdout) logger.level = Logger::ERROR unless ENV['DEBUG'] logger end end |
.run_command(*args) ⇒ string
Run an soffice command
63 64 65 66 67 68 69 70 71 |
# File 'lib/word-to-markdown.rb', line 63 def run_command(*args) raise 'LibreOffice already running' if soffice.open? output, status = Open3.capture2e(soffice.path, *args) logger.debug output raise "Command `#{soffice.path} #{args.join(' ')}` failed: #{output}" if status.exitstatus != 0 output end |
.soffice ⇒ Object
Returns a Cliver::Dependency object representing our soffice dependency
Attempts to resolve by looking at PATH followed by paths in the PATHS constant
Methods used internally:
path - returns the resolved path. Raises an error if not satisfied
version - returns the resolved version
open - is the dependency currently open/running?
82 83 84 |
# File 'lib/word-to-markdown.rb', line 82 def soffice @soffice ||= Cliver::Dependency.new('soffice', *soffice_dependency_args) end |
Instance Method Details
#to_s ⇒ string
Helper method to return the document body, as markdown
54 55 56 |
# File 'lib/word-to-markdown.rb', line 54 def to_s document.to_s end |