Class: OdfFile
- Inherits:
-
Object
- Object
- OdfFile
- Defined in:
- lib/documenter/ooo/odf.rb
Direct Known Subclasses
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(filename) ⇒ OdfFile
constructor
A new instance of OdfFile.
- #load_xml ⇒ Object
- #random_name ⇒ Object
- #save(filename) ⇒ Object
- #save_xml(xml) ⇒ Object
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
#close ⇒ Object
31 32 33 34 |
# File 'lib/documenter/ooo/odf.rb', line 31 def close File.delete @content File.delete @file end |
#load_xml ⇒ Object
21 22 23 |
# File 'lib/documenter/ooo/odf.rb', line 21 def load_xml File.read(@content) end |
#random_name ⇒ Object
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 |