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 }
- VERSION =
"1.0.0"
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
-
.run_command(*args) ⇒ Object
Ideally this would be done via open3, but Travis CI can’t seen to find soffice when we do.
- .soffice_path ⇒ Object
- .soffice_version ⇒ Object
- .which(cmd) ⇒ Object
Instance Method Summary collapse
-
#initialize(path) ⇒ WordToMarkdown
constructor
Create a new WordToMarkdown object.
-
#inspect ⇒ Object
Pretty print the class in console.
- #to_s ⇒ Object
Constructor Details
#initialize(path) ⇒ WordToMarkdown
Create a new WordToMarkdown object
input - a HTML string or path to an HTML file
Returns the WordToMarkdown object
26 27 28 29 30 |
# File 'lib/word-to-markdown.rb', line 26 def initialize(path) @document = WordToMarkdown::Document.new path @converter = WordToMarkdown::Converter.new @document converter.convert! end |
Instance Attribute Details
#converter ⇒ Object (readonly)
Returns the value of attribute converter.
14 15 16 |
# File 'lib/word-to-markdown.rb', line 14 def converter @converter end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
14 15 16 |
# File 'lib/word-to-markdown.rb', line 14 def document @document end |
Class Method Details
.run_command(*args) ⇒ Object
Ideally this would be done via open3, but Travis CI can’t seen to find soffice when we do
56 57 58 |
# File 'lib/word-to-markdown.rb', line 56 def self.run_command(*args) `#{soffice_path} #{args.join(' ')}` end |
.soffice_path ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/word-to-markdown.rb', line 45 def self.soffice_path if RUBY_PLATFORM.include?("darwin") "/Applications/LibreOffice.app/Contents/MacOS/soffice" else soffice_path ||= which("soffice") soffice_path ||= which("soffice.bin") soffice_path ||= "soffice" end end |
.soffice_version ⇒ Object
60 61 62 |
# File 'lib/word-to-markdown.rb', line 60 def self.soffice_version run_command('--version').strip.sub "LibreOffice ", "" end |
.which(cmd) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/word-to-markdown.rb', line 33 def self.which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable? exe end end return nil end |
Instance Method Details
#inspect ⇒ Object
Pretty print the class in console
65 66 67 |
# File 'lib/word-to-markdown.rb', line 65 def inspect "<WordToMarkdown path=\"#{@document.path}\">" end |
#to_s ⇒ Object
69 70 71 |
# File 'lib/word-to-markdown.rb', line 69 def to_s document.to_s end |