Class: RubyXL::GenericStorageObject
- Inherits:
-
Object
- Object
- RubyXL::GenericStorageObject
- Defined in:
- lib/rubyXL/objects/storage.rb
Direct Known Subclasses
BinaryImageFile, ChartColorsFile, ChartFile, ChartStyleFile, ChartUserShapesFile, ControlPropertiesFile, CustomPropertiesFile, CustomXMLFile, DrawingFile, ExternalLinksFile, HyperlinkRelFile, MacrosFile, PivotCacheDefinitionFile, PivotTableFile, PrinterSettingsFile, SlicerCacheFile, SlicerFile, TableFile, ThumbnailFile, VMLDrawingFile
Constant Summary collapse
- SAVE_ORDER =
0
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#generic_storage ⇒ Object
Returns the value of attribute generic_storage.
-
#xlsx_path ⇒ Object
Returns the value of attribute xlsx_path.
Class Method Summary collapse
Instance Method Summary collapse
- #add_to_zip(zip_stream) ⇒ Object
-
#initialize(file_path) ⇒ GenericStorageObject
constructor
A new instance of GenericStorageObject.
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
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/rubyXL/objects/storage.rb', line 6 def data @data end |
#generic_storage ⇒ Object
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_path ⇒ Object
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 |