class Spreadsheet

1 Object of this class manipulates 1 spreadsheet-file at a time

Attributes

options[W]
sheets[R]

Public Class Methods

new() click to toggle source
# File spreadsheet.rb, line 38
def initialize
  @log = @@log
  @log.debug("initialize")
  # REMINDER call the attr_writer on options
  @options = nil
end

Public Instance Methods

cleanup() click to toggle source

If needed.

# File spreadsheet.rb, line 88
def cleanup
  # Close the InputStream
  @spr_in.close
end
file=(fl) click to toggle source

Set the file and do the necessary.

# File spreadsheet.rb, line 46
def file=(fl)
  dirname = File::absolute_path(File::dirname(fl) )
  @file = File::absolute_path(fl)
  @log.debug('spreadsheet file is ' << @file << ", dirname is " << dirname)
  
  # create a copy of the original file, if demanded.
  # FOR THE TIME BEING, THE COPY IS ALWAYS CREATED.
  
  # if(@options.backup)
  File::binwrite(File.join(dirname.dup, "BAK_" << File.basename(fl)), File::binread(@file ) )
  #end

  # read the zipped spreadsheet
  find_entries
end
sheet(attr = 1) click to toggle source
# File spreadsheet.rb, line 62
def sheet(attr = 1)
  if(attr.respond_to?(:to_str))
    @sheets.detect {|s| s.name == attr } 
  elsif (attr.respond_to?(:to_i) )
    @sheets.detect {|s| s.id == attr}
  end
end
update_sheet(sheet) click to toggle source
# File spreadsheet.rb, line 70
def update_sheet(sheet)
  @log.debug('updating sheet ' << sheet.zip_entry << ' in file ' << @file)
  # Zip::File.replace needs a file but looks cool, otherwise.
  # Create the file.
  td = Dir.mktmpdir
  tfile = File.join(td, 't_sheet')
  File.write(tfile, sheet.table)

  # substitute the original with the temporary file.
  Zip::File.open(@file) do |ofl|
    ofl.replace(sheet.zip_entry, tfile)
  end
  # remove temporary file and -directory
  File.unlink(tfile)
  Dir.rmdir(td)
end