class Rubyxls::Report
Attributes
file_name[R]
workbooks[R]
Public Class Methods
new()
click to toggle source
# File lib/rubyxls/report.rb, line 7 def initialize @workbooks = [] @file_name = 'rubyxls' build_workbooks! end
Public Instance Methods
content_type()
click to toggle source
# File lib/rubyxls/report.rb, line 33 def content_type if file_extension == :xlsx 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' elsif file_extension == :zip 'application/zip' end end
download!()
click to toggle source
# File lib/rubyxls/report.rb, line 13 def download! if @workbooks.size == 1 @workbooks.first.to_stream else stream = StringIO.new zipfile = Zip::File.new(stream, true, true) @workbooks.each do |workbook| zipfile.get_output_stream(workbook.filename) { |zipstream| IO.copy_stream(workbook.to_stream, zipstream) } end zipfile.write_buffer(stream) zipfile.glob('*', &:clean_up) stream.rewind stream end end
file_extension()
click to toggle source
# File lib/rubyxls/report.rb, line 29 def file_extension @workbooks.size > 1 ? :zip : :xlsx end
Private Instance Methods
build_workbooks!()
click to toggle source
# File lib/rubyxls/report.rb, line 43 def build_workbooks! @workbooks << Rubyxls::Workbook.new end