Class: RubyXL::GenericStorageObject

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyXL/objects/storage.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGenericStorageObject

Returns a new instance of GenericStorageObject.



7
8
9
10
11
12
# File 'lib/rubyXL/objects/storage.rb', line 7

def initialize
  @workbook = nil
  @xlsx_path = nil
  @data = nil
  @generic_storage = []
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/rubyXL/objects/storage.rb', line 5

def data
  @data
end

#generic_storageObject

Returns the value of attribute generic_storage.



5
6
7
# File 'lib/rubyXL/objects/storage.rb', line 5

def generic_storage
  @generic_storage
end

#workbookObject

Returns the value of attribute workbook.



5
6
7
# File 'lib/rubyXL/objects/storage.rb', line 5

def workbook
  @workbook
end

#xlsx_pathObject

Returns the value of attribute xlsx_path.



5
6
7
# File 'lib/rubyXL/objects/storage.rb', line 5

def xlsx_path
  @xlsx_path
end

Class Method Details

.parse_file(dirpath, file_path = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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_orderObject



14
15
16
# File 'lib/rubyXL/objects/storage.rb', line 14

def self.save_order
  0
end

Instance Method Details

#add_to_zip(zipfile) ⇒ Object



37
38
39
40
41
42
43
44
# 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