Class: Rspreadsheet::WorkbookFlat
- Defined in:
- lib/rspreadsheet/workbook.rb
Instance Attribute Summary
Attributes inherited from Workbook
Loading and saving related methods collapse
- #flat_format? ⇒ Boolean
-
#initialize(afilename = nil) ⇒ WorkbookFlat
constructor
A new instance of WorkbookFlat.
- #normal_format? ⇒ Boolean
- #save(io = nil) ⇒ Object (also: #save_to_io, #save_as)
Methods inherited from Workbook
#mime, #mime_preferred_extension, #to_io, #write_ods_to_io
Methods inherited from Workbook
#[], #create_worksheet, #create_worksheet_from_node, #worksheet_names, #worksheets, #worksheets_count, #xmldoc
Constructor Details
#initialize(afilename = nil) ⇒ WorkbookFlat
Returns a new instance of WorkbookFlat.
193 194 195 196 197 198 199 200 201 |
# File 'lib/rspreadsheet/workbook.rb', line 193 def initialize(afilename=nil) @worksheets=[] @filename = afilename @xml_doc = LibXML::XML::Document.file(@filename || FLAT_TEMPLATE_FILE_NAME) @xmlnode = @xml_doc.find_first('//office:spreadsheet') @xmlnode.find('./table:table').each do |node| create_worksheet_from_node(node) end end |
Instance Method Details
#flat_format? ⇒ Boolean
221 |
# File 'lib/rspreadsheet/workbook.rb', line 221 def flat_format?; true end |
#normal_format? ⇒ Boolean
222 |
# File 'lib/rspreadsheet/workbook.rb', line 222 def normal_format?; false end |
#save(io = nil) ⇒ Object Also known as: save_to_io, save_as
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/rspreadsheet/workbook.rb', line 203 def save(io=nil) case when @filename.nil? && io.nil? raise 'New file should be named on first save, please provide filename (or IO).' when @filename.kind_of?(String) && io.nil? @xml_doc.save(@filename) when (@filename.kind_of?(String) && (io.kind_of?(String) || io.kind_of?(File))) @filename = (io.kind_of?(File)) ? io.path : io @xml_doc.save(@filename) when io.kind_of?(IO) || io.kind_of?(String) || io.kind_of?(StringIO) IO.write(io,@xml_doc.to_s) io.rewind if io.kind_of?(StringIO) else raise 'Invalid combinations of parameter types in save' end end |