Class: RubyXL::GenericStorage
- Inherits:
-
Hash
- Object
- Hash
- RubyXL::GenericStorage
- Defined in:
- lib/rubyXL/generic_storage.rb
Instance Attribute Summary collapse
-
#local_dir_path ⇒ Object
readonly
Returns the value of attribute local_dir_path.
Instance Method Summary collapse
- #add_to_zip(zipfile) ⇒ Object
- #binary ⇒ Object
-
#initialize(local_dir_path) ⇒ GenericStorage
constructor
A new instance of GenericStorage.
- #load_dir(root_dir) ⇒ Object
- #load_file(root_dir, filename) ⇒ Object
Constructor Details
#initialize(local_dir_path) ⇒ GenericStorage
Returns a new instance of GenericStorage.
5 6 7 8 9 |
# File 'lib/rubyXL/generic_storage.rb', line 5 def initialize(local_dir_path) @local_dir_path = local_dir_path @mode = 'r' super end |
Instance Attribute Details
#local_dir_path ⇒ Object (readonly)
Returns the value of attribute local_dir_path.
3 4 5 |
# File 'lib/rubyXL/generic_storage.rb', line 3 def local_dir_path @local_dir_path end |
Instance Method Details
#add_to_zip(zipfile) ⇒ Object
33 34 35 36 37 |
# File 'lib/rubyXL/generic_storage.rb', line 33 def add_to_zip(zipfile) each_pair { |filename, data| zipfile.get_output_stream(File.join(@local_dir_path, filename)) { |f| f << data } } end |
#binary ⇒ Object
11 12 13 14 |
# File 'lib/rubyXL/generic_storage.rb', line 11 def binary @mode = 'rb' self end |
#load_dir(root_dir) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rubyXL/generic_storage.rb', line 16 def load_dir(root_dir) dirpath = File.join(root_dir, @local_dir_path) if File.directory?(dirpath) then (Dir.new(dirpath).entries - ['.', '..', '.DS_Store', '_rels']).each { |filename| self[filename] = File.open(File.join(dirpath, filename), @mode).read } end self end |
#load_file(root_dir, filename) ⇒ Object
27 28 29 30 31 |
# File 'lib/rubyXL/generic_storage.rb', line 27 def load_file(root_dir, filename) filepath = File.join(root_dir, @local_dir_path, filename) self[filename] = File.open(filepath, @mode).read if File.readable?(filepath) self end |