Class: ExcelAbstraction::SpreadSheet

Inherits:
Tempfile
  • Object
show all
Defined in:
lib/excel_templating/excel_abstraction/spread_sheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format: :xls, skip_default_sheet: false) ⇒ SpreadSheet

Returns a new instance of SpreadSheet.



7
8
9
10
11
12
# File 'lib/excel_templating/excel_abstraction/spread_sheet.rb', line 7

def initialize(format: :xls, skip_default_sheet: false)
  extension = format == :xls ? ".xls" : ".xlsx"
  tmp_file = Tempfile.new(["temp_spreadsheet_#{::Time.now.to_i}", extension])
  super(tmp_file)
  @workbook = ExcelAbstraction::WorkBook.new(tmp_file.path, format: format, skip_default_sheet: skip_default_sheet)
end

Instance Attribute Details

#workbookObject (readonly)

Returns the value of attribute workbook.



5
6
7
# File 'lib/excel_templating/excel_abstraction/spread_sheet.rb', line 5

def workbook
  @workbook
end

Instance Method Details

#closeObject



14
15
16
17
18
# File 'lib/excel_templating/excel_abstraction/spread_sheet.rb', line 14

def close
  workbook.close
  yield if block_given?
  super
end

#to_sObject



20
21
22
23
24
25
26
# File 'lib/excel_templating/excel_abstraction/spread_sheet.rb', line 20

def to_s
  data = nil
  close do
    data = read
  end
  data
end