Class: XlsxWriter::Document
- Inherits:
-
Object
- Object
- XlsxWriter::Document
- Defined in:
- lib/xlsx_writer/document.rb
Instance Attribute Summary collapse
-
#header_footer ⇒ Object
readonly
Returns the value of attribute header_footer.
-
#images ⇒ Object
readonly
Returns the value of attribute images.
-
#page_setup ⇒ Object
readonly
Returns the value of attribute page_setup.
-
#sheets ⇒ Object
readonly
Returns the value of attribute sheets.
-
#staging_dir ⇒ Object
readonly
Returns the value of attribute staging_dir.
Class Method Summary collapse
Instance Method Summary collapse
- #add_image(path, width, height) ⇒ Object
- #add_sheet(name) ⇒ Object
- #cleanup ⇒ Object
- #generate ⇒ Object
- #generated? ⇒ Boolean
-
#initialize ⇒ Document
constructor
A new instance of Document.
- #path ⇒ Object
Constructor Details
#initialize ⇒ Document
Returns a new instance of Document.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/xlsx_writer/document.rb', line 21 def initialize staging_dir = ::UnixUtils.tmp_path 'xlsx_writer' ::FileUtils.mkdir_p staging_dir @staging_dir = staging_dir @sheets = [] @images = [] @page_setup = PageSetup.new @header_footer = HeaderFooter.new @mutex = ::Mutex.new end |
Instance Attribute Details
#header_footer ⇒ Object (readonly)
Returns the value of attribute header_footer.
19 20 21 |
# File 'lib/xlsx_writer/document.rb', line 19 def @header_footer end |
#images ⇒ Object (readonly)
Returns the value of attribute images.
17 18 19 |
# File 'lib/xlsx_writer/document.rb', line 17 def images @images end |
#page_setup ⇒ Object (readonly)
Returns the value of attribute page_setup.
18 19 20 |
# File 'lib/xlsx_writer/document.rb', line 18 def page_setup @page_setup end |
#sheets ⇒ Object (readonly)
Returns the value of attribute sheets.
16 17 18 |
# File 'lib/xlsx_writer/document.rb', line 16 def sheets @sheets end |
#staging_dir ⇒ Object (readonly)
Returns the value of attribute staging_dir.
15 16 17 |
# File 'lib/xlsx_writer/document.rb', line 15 def staging_dir @staging_dir end |
Class Method Details
.auto ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/xlsx_writer/document.rb', line 6 def auto ::Dir[::File.('../generators/*.rb', __FILE__)].map do |path| XlsxWriter.const_get ::File.basename(path, '.rb').camelcase end.reject do |klass| klass.const_defined?(:AUTO) and klass.const_get(:AUTO) == false end end |
Instance Method Details
#add_image(path, width, height) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/xlsx_writer/document.rb', line 41 def add_image(path, width, height) raise ::RuntimeError, "Can't add image, already generated!" if generated? image = Image.new self, path, width, height images << image image end |
#add_sheet(name) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/xlsx_writer/document.rb', line 32 def add_sheet(name) raise ::RuntimeError, "Can't add sheet, already generated!" if generated? sheet = Sheet.new self, name sheets << sheet sheet end |
#cleanup ⇒ Object
65 66 67 68 |
# File 'lib/xlsx_writer/document.rb', line 65 def cleanup ::FileUtils.rm_rf @staging_dir.to_s ::FileUtils.rm_f @path.to_s end |
#generate ⇒ Object
70 71 72 73 |
# File 'lib/xlsx_writer/document.rb', line 70 def generate path true end |
#generated? ⇒ Boolean
75 76 77 |
# File 'lib/xlsx_writer/document.rb', line 75 def generated? @generated == true end |
#path ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/xlsx_writer/document.rb', line 48 def path @path || @mutex.synchronize do @path ||= begin sheets.each(&:generate) images.each(&:generate) Document.auto.each do |part| part.new(self).generate end with_zip_extname = ::UnixUtils.zip staging_dir with_xlsx_extname = with_zip_extname.sub(/.zip$/, '.xlsx') ::FileUtils.mv with_zip_extname, with_xlsx_extname @generated = true with_xlsx_extname end end end |