Class: WordToMarkdown

Inherits:
Object
  • Object
show all
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

Classes: Converter, Document

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

Class Method Summary collapse

Instance Method Summary collapse

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

#converterObject (readonly)

Returns the value of attribute converter.



20
21
22
# File 'lib/word-to-markdown.rb', line 20

def converter
  @converter
end

#documentObject (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

.loggerObject



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

.sofficeObject

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

#inspectObject

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_sObject



82
83
84
# File 'lib/word-to-markdown.rb', line 82

def to_s
  document.to_s
end