Class: RubyXL::GenericStorageObject

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

Constant Summary collapse

SAVE_ORDER =
0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ GenericStorageObject

Returns a new instance of GenericStorageObject.



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

def initialize(file_path)
  @xlsx_path = file_path
  @data = nil
  @generic_storage = []
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



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

def data
  @data
end

#generic_storageObject

Returns the value of attribute generic_storage.



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

def generic_storage
  @generic_storage
end

#xlsx_pathObject

Returns the value of attribute xlsx_path.



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

def xlsx_path
  @xlsx_path
end

Class Method Details

.parse_file(dirpath, file_path = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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

Instance Method Details

#add_to_zip(zip_stream) ⇒ Object



33
34
35
36
37
38
39
# 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