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 =
{ unknown_tags: :bypass, github_flavored: true }
- SOFFICE_VERSION_REQUIREMENT =
'> 4.0'
- PATHS =
[ "*", # 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" ]
- VERSION =
"1.1.7"
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
- .run_command(*args) ⇒ Object
-
.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.
-
#inspect ⇒ Object
Pretty print the class in console.
- #to_s ⇒ Object
Constructor Details
#initialize(path, tmpdir = nil) ⇒ WordToMarkdown
Create a new WordToMarkdown object
input - a HTML string or path to an HTML file
Returns the WordToMarkdown object
42 43 44 45 46 |
# File 'lib/word-to-markdown.rb', line 42 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.
20 21 22 |
# File 'lib/word-to-markdown.rb', line 20 def converter @converter end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
20 21 22 |
# File 'lib/word-to-markdown.rb', line 20 def document @document end |
Class Method Details
.logger ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/word-to-markdown.rb', line 69 def self.logger @@logger ||= begin logger = Logger.new(STDOUT) logger.level = Logger::ERROR unless ENV["DEBUG"] logger end end |
.run_command(*args) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/word-to-markdown.rb', line 48 def self.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?
65 66 67 |
# File 'lib/word-to-markdown.rb', line 65 def self.soffice @@soffice_dependency ||= Cliver::Dependency.new("soffice", *soffice_dependency_args) end |
Instance Method Details
#inspect ⇒ Object
Pretty print the class in console
78 79 80 |
# File 'lib/word-to-markdown.rb', line 78 def inspect "<WordToMarkdown path=\"#{@document.path}\">" end |
#to_s ⇒ Object
82 83 84 |
# File 'lib/word-to-markdown.rb', line 82 def to_s document.to_s end |