Class: Doc2Text::Odt::Document

Inherits:
XmlBasedDocument::DocumentFile show all
Defined in:
lib/doc2text/odt/odt.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from XmlBasedDocument::DocumentFile

#clean, #extract_path, #initialize, #open, #unpack

Constructor Details

This class inherits a constructor from Doc2Text::XmlBasedDocument::DocumentFile

Class Method Details

.parse_and_save(input, output_filename) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/doc2text/odt/odt.rb', line 9

def self.parse_and_save(input, output_filename)
  odt = new input
  begin
    odt.unpack
    styles_xml_root = odt.parse_styles
    output = File.open output_filename, 'w'
    markdown = Markdown::OdtParser.new output, styles_xml_root
    begin
      odt.parse markdown
    ensure
      markdown.close
    end
  ensure
    odt.clean
  end
end

Instance Method Details

#contains_extracted_files?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/doc2text/odt/odt.rb', line 38

def contains_extracted_files?
  [File.join(extract_path, 'content.xml'), File.join(extract_path, 'mimetype')].all? { |file| File.exist?(file) }
end

#extract_extensionObject



5
6
7
# File 'lib/doc2text/odt/odt.rb', line 5

def extract_extension
  'unpacked_odt'
end

#parse(markdown) ⇒ Object



33
34
35
36
# File 'lib/doc2text/odt/odt.rb', line 33

def parse(markdown)
  parser = Nokogiri::XML::SAX::Parser.new(markdown) # { |config| config.strict}
  parser.parse open 'content.xml'
end

#parse_stylesObject



26
27
28
29
30
31
# File 'lib/doc2text/odt/odt.rb', line 26

def parse_styles
  styles_parser = Doc2Text::Odt::StylesParser.new
  xml = Nokogiri::XML::SAX::Parser.new(styles_parser)
  xml.parse open 'styles.xml'
  styles_parser.xml_root
end