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.1.1"
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
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
28 29 30 31 32 |
# File 'lib/word-to-markdown.rb', line 28 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.
16 17 18 |
# File 'lib/word-to-markdown.rb', line 16 def converter @converter end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
16 17 18 |
# File 'lib/word-to-markdown.rb', line 16 def document @document end |
Class Method Details
.os ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/word-to-markdown.rb', line 35 def self.os @os ||= ( host_os = RbConfig::CONFIG['host_os'] case host_os when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ :windows when /darwin|mac os/ :macosx when /linux/ :linux when /solaris|bsd/ :unix else raise Error::WebDriverError, "unknown os: #{host_os.inspect}" end ) end |
.run_command(*args) ⇒ Object
66 67 68 69 70 |
# File 'lib/word-to-markdown.rb', line 66 def self.run_command(*args) output, status = Open3.capture2e(soffice_path, *args) raise "Command `#{soffice_path} #{args.join(" ")}` failed: #{output}" if status != 0 output end |
.soffice_path ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/word-to-markdown.rb', line 53 def self.soffice_path case os when :macosx %w[~/Applications /Applications] .map { |f| File.(File.join(f, "/LibreOffice.app/Contents/MacOS/soffice")) } .find { |f| File.file?(f) } when :windows 'C:\Program Files (x86)\LibreOffice 4\program\soffice.exe' else "soffice" end end |
.soffice_version ⇒ Object
72 73 74 |
# File 'lib/word-to-markdown.rb', line 72 def self.soffice_version run_command('--version').strip.sub "LibreOffice ", "" end |
Instance Method Details
#inspect ⇒ Object
Pretty print the class in console
77 78 79 |
# File 'lib/word-to-markdown.rb', line 77 def inspect "<WordToMarkdown path=\"#{@document.path}\">" end |
#to_s ⇒ Object
81 82 83 |
# File 'lib/word-to-markdown.rb', line 81 def to_s document.to_s end |