class Doc2Text::XmlBasedDocument::DocumentFile

Public Class Methods

new(document_path) click to toggle source
# File lib/doc2text/xml_based_document_file.rb, line 6
def initialize(document_path)
  @document_path = document_path
end

Public Instance Methods

clean() click to toggle source
# File lib/doc2text/xml_based_document_file.rb, line 26
def clean
  if File.exist?(extract_path) and contains_extracted_files?
    FileUtils.rm_r extract_path
  else
    puts 'Failed to clean temp files'
  end
end
contains_extracted_files?() click to toggle source
# File lib/doc2text/xml_based_document_file.rb, line 22
def contains_extracted_files?
  false
end
extract_extension() click to toggle source
# File lib/doc2text/xml_based_document_file.rb, line 39
def extract_extension
  'unpacked'
end
extract_path() click to toggle source
# File lib/doc2text/xml_based_document_file.rb, line 43
def extract_path
  File.join File.dirname(@document_path), ".#{File.basename(@document_path)}_#{extract_extension}"
end
open(filename) click to toggle source

Open file from the current odt

# File lib/doc2text/xml_based_document_file.rb, line 35
def open(filename)
  File.open File.join(extract_path, filename), 'r'
end
unpack() click to toggle source
# File lib/doc2text/xml_based_document_file.rb, line 10
def unpack
  Zip::File.open(@document_path) {
      |zip_file|
    Dir.mkdir(extract_path)
    zip_file.each do |entry|
      zipped_file_extract_path = File.join extract_path, entry.name
      FileUtils.mkdir_p File.dirname(zipped_file_extract_path)
      zip_file.extract entry, zipped_file_extract_path
    end
  }
end