class RubyXL::GenericStorageObject

Attributes

data[RW]
generic_storage[RW]
workbook[RW]
xlsx_path[RW]

Public Class Methods

new() click to toggle source
# File lib/rubyXL/objects/storage.rb, line 7
def initialize
  @workbook = nil
  @xlsx_path = nil
  @data = nil
  @generic_storage = []
end
parse_file(dirpath, file_path = nil) click to toggle source
# File lib/rubyXL/objects/storage.rb, line 18
def self.parse_file(dirpath, file_path = nil)
  file_path ||= self.xlsx_path
  obj = self.new

  case dirpath
  when String then
    full_path = File.join(dirpath, file_path)
    return nil unless File.exist?(full_path)
    obj.data = File.open(full_path, 'r') { |f| f.read }
  when Zip::File then
    entry = dirpath.find_entry(file_path)
    return nil if entry.nil?
    obj.data = entry.get_input_stream { |f| f.read }
  end

  obj.xlsx_path = file_path
  obj
end
save_order() click to toggle source
# File lib/rubyXL/objects/storage.rb, line 14
def self.save_order
  0
end

Public Instance Methods

add_to_zip(zipfile) click to toggle source
# File lib/rubyXL/objects/storage.rb, line 37
def add_to_zip(zipfile)
  return if @data.nil?

  path = self.xlsx_path
  path = path.relative_path_from(Pathname.new("/")) if path.absolute? # Zip doesn't like absolute paths.


  zipfile.get_output_stream(path) { |f| f << @data }
end