Class: Spreadsheetkit::Sheet

Inherits:
Object
  • Object
show all
Defined in:
lib/spreadsheetkit/sheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, options = {}) ⇒ Sheet

Returns a new instance of Sheet.



6
7
8
9
10
11
12
# File 'lib/spreadsheetkit/sheet.rb', line 6

def initialize(table, options = {})
  @table = table
  
  @rows = []
  @table.css("tr").each{ |tr| @rows << Spreadsheetkit::Row.new(tr) }
  @title = @table[:title]
end

Instance Attribute Details

#rowsObject

Returns the value of attribute rows.



4
5
6
# File 'lib/spreadsheetkit/sheet.rb', line 4

def rows
  @rows
end

#sheetObject

Returns the value of attribute sheet.



4
5
6
# File 'lib/spreadsheetkit/sheet.rb', line 4

def sheet
  @sheet
end

#tableObject

Returns the value of attribute table.



4
5
6
# File 'lib/spreadsheetkit/sheet.rb', line 4

def table
  @table
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/spreadsheetkit/sheet.rb', line 4

def title
  @title
end

Instance Method Details

#render(xls) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/spreadsheetkit/sheet.rb', line 14

def render(xls)
  @sheet = xls.create_worksheet
  @sheet.name = @title unless @title.blank?
  
  @rows.each_with_index do |row, row_x| 
    row.render @sheet.row(row_x)
  end
end