Class: OdfFile

Inherits:
Object
  • Object
show all
Defined in:
lib/documenter/ooo/odf.rb

Direct Known Subclasses

OdtFile

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ OdfFile

Returns a new instance of OdfFile.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/documenter/ooo/odf.rb', line 9

def initialize filename
	#working with copy 
   ext = filename.split('.')[-1]
	rn = random_name
	@file = random_name+'tmp.'+ext
	@content = random_name+'tmp.xml'
	
	File.copy filename, @file
	zip  = Zip::ZipFile.open(@file)
	zip.extract('content.xml',@content)	
end

Instance Method Details

#closeObject



31
32
33
34
# File 'lib/documenter/ooo/odf.rb', line 31

def close
	File.delete @content
	File.delete @file
end

#load_xmlObject



21
22
23
# File 'lib/documenter/ooo/odf.rb', line 21

def load_xml
	File.read(@content)
end

#random_nameObject



5
6
7
# File 'lib/documenter/ooo/odf.rb', line 5

def random_name 
	Time.now.strftime('%H%M%S')+rand(100000).to_s
end

#save(filename) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/documenter/ooo/odf.rb', line 36

def save filename
	zip  = Zip::ZipFile.open(@file) 
   puts "just before saving"
	zip.replace('content.xml',@content)
	zip.close
   if filename.split('.')[-1]=='odt'
     File.copy @file, filename
   else
     Converter.convert @file, filename
   end
   
end

#save_xml(xml) ⇒ Object



25
26
27
28
29
# File 'lib/documenter/ooo/odf.rb', line 25

def save_xml xml
	File.open(@content,'w') do |f|
		f.write xml
	end
end