Class: DocxConverter::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/docx_converter/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Parser

Returns a new instance of Parser.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/docx_converter/parser.rb', line 22

def initialize(options)
  @output_dir = options[:output_dir]
  @docx_filepath = options[:inputfile]
  
  @image_subdir_filesystem = options[:image_subdir_filesystem]
  @image_subdir_kramdown = options[:image_subdir_kramdown]
  
  @relationships_hash = {}
  
  @zipfile = Zip::ZipFile.new(@docx_filepath)
end

Instance Method Details

#parseObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/docx_converter/parser.rb', line 34

def parse
  document_xml = unzip_read("word/document.xml")
  footnotes_xml = unzip_read("word/footnotes.xml")
  relationships_xml = unzip_read("word/_rels/document.xml.rels")
  
  content = Nokogiri::XML(document_xml)
  footnotes = Nokogiri::XML(footnotes_xml)
  relationships = Nokogiri::XML(relationships_xml)
  
  @relationships_hash = parse_relationships(relationships)

  footnote_definitions = parse_footnotes(footnotes)
  output_content = parse_content(content.elements.first,0)
  
  return {
    :content => output_content,
    :footnote_definitions => footnote_definitions
  }
end