class RubyXL::GenericStorageObject

Constants

SAVE_ORDER

Attributes

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

Public Class Methods

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

  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
    file_path = file_path.relative_path_from(::Pathname.new("/")) if file_path.absolute? # Zip doesn't like absolute paths.

    entry = dirpath.find_entry(file_path)
    return nil if entry.nil?
    obj.data = entry.get_input_stream { |f| f.read }
  end

  obj
end

Public Instance Methods

add_to_zip(zip_stream) click to toggle source
# File lib/rubyXL/objects/storage.rb, line 33
def add_to_zip(zip_stream)
  return if @data.nil?
  path = self.xlsx_path
  path = path.relative_path_from(Pathname.new("/")) if path.absolute? # Zip doesn't like absolute paths.

  zip_stream.put_next_entry(path)
  zip_stream.write(@data)
end