Class: ExcelSerializer::Worksheet

Inherits:
Object
  • Object
show all
Defined in:
lib/excel_serializer/worksheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_excel, sheet_name) ⇒ Worksheet

Returns a new instance of Worksheet.



5
6
7
8
# File 'lib/excel_serializer/worksheet.rb', line 5

def initialize(current_excel, sheet_name)
  @sheet = current_excel.add_worksheet(sheet_name)
  @row_counter = 0
end

Instance Attribute Details

#row_counterObject

Returns the value of attribute row_counter.



3
4
5
# File 'lib/excel_serializer/worksheet.rb', line 3

def row_counter
  @row_counter
end

#sheetObject

Returns the value of attribute sheet.



3
4
5
# File 'lib/excel_serializer/worksheet.rb', line 3

def sheet
  @sheet
end

Instance Method Details

#write_headers(headers) ⇒ Object



17
18
19
20
21
# File 'lib/excel_serializer/worksheet.rb', line 17

def write_headers(headers)
  headers.each_with_index do |value, current_column|
    @sheet.write(0, current_column, value)
  end
end

#write_row(row) ⇒ Object



10
11
12
13
14
15
# File 'lib/excel_serializer/worksheet.rb', line 10

def write_row(row)
  row_index = @row_counter += 1
  row.each_with_index do |value, current_column|
    @sheet.write(row_index, current_column, value)
  end
end