Class: Woa::Energon::OpenDocumentHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/energon/open_document_helper.rb

Overview

This class is an interface with OpenDocument files. It manages the content of the file so that caller classes just manage xml Objects (ReXml). It’s not possible at this time to work with streams beacause of the zip library (rubyzip), it has to be done via files.

:include: rdoc-header

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template) ⇒ OpenDocumentHelper

  • template: the name of the file

Raises:



24
25
26
27
28
# File 'lib/energon/open_document_helper.rb', line 24

def initialize(template)
  @zip_file = ZipFile.open(template)
  @content = xml(read("content.xml")) rescue nil
  raise InvalidODFDocument if @content.nil?
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



21
22
23
# File 'lib/energon/open_document_helper.rb', line 21

def content
  @content
end

#typeObject (readonly)

Returns the value of attribute type.



21
22
23
# File 'lib/energon/open_document_helper.rb', line 21

def type
  @type
end

Instance Method Details

#save(content) ⇒ Object

Save the file content.xml

  • content: the xml Object (ReXml)



32
33
34
35
# File 'lib/energon/open_document_helper.rb', line 32

def save(content)
  @content = content
  save_xml(@content, "content.xml");
end

#writeObject Also known as: close

Write the final document (the zipfile) and close the file



38
39
40
# File 'lib/energon/open_document_helper.rb', line 38

def write
  @zip_file.close
end