class SpreadBase::Document
Represents the abstraction of a document, merging both the file and the document metadata concepts.
Attributes
document_path[RW]
tables[RW]
Public Class Methods
new(document_path=nil, options={})
click to toggle source
params:
document_path
-
(nil)
Document
path; if not passed, an empty document is created.
options:
floats_as_bigdecimal
-
(false) decode floats as BigDecimal instead of Float
# File lib/spreadbase/document.rb, line 27 def initialize(document_path=nil, options={}) @document_path = document_path @options = options.clone if @document_path && File.exist?(document_path) document_archive = IO.read(document_path) decoded_document = Codecs::OpenDocument12.new.decode_archive(document_archive, options) @column_width_styles = decoded_document.column_width_styles @tables = decoded_document.tables else @column_width_styles = [] @tables = [] end end
Public Instance Methods
save(options={})
click to toggle source
Saves the document to the disk; before saving, it's required:
-
to have at least one table
-
to have set the documenth path, either during the initialization, or using the
document_path
accessor.
options:
prettify
-
Prettifies the content.xml file before saving.
# File lib/spreadbase/document.rb, line 51 def save(options={}) options = @options.merge(options) raise "At least one table must be present" if @tables.empty? raise "Document path not specified" if @document_path.nil? document_archive = Codecs::OpenDocument12.new.encode_to_archive(self, options) File.open(@document_path, 'wb') { | file | file << document_archive } end
to_s(options={})
click to toggle source
options:
with_headers
-
Print the tables with headers.
# File lib/spreadbase/document.rb, line 66 def to_s(options={}) options.merge!(row_prefix: ' ') tables.inject('') do | output, table | output << "#{ table.name }:" << "\n" << "\n" output << table.to_s(options) << "\n" end end