Class: Spreadsheetkit::Row

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tr) ⇒ Row

Returns a new instance of Row.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/spreadsheetkit/row.rb', line 6

def initialize(tr)
  @tr = tr
  @format = Spreadsheetkit::Format.new(@tr)
  
  @cells = []
  @tr.css("td, th").each do|td| 
    cell = Spreadsheetkit::Cell.new(td)
    @merge = true if cell.merge?
    @cells << cell
  end
end

Instance Attribute Details

#cellsObject (readonly)

Returns the value of attribute cells.



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

def cells
  @cells
end

#formatObject (readonly)

Returns the value of attribute format.



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

def format
  @format
end

#mergeObject (readonly)

Returns the value of attribute merge.



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

def merge
  @merge
end

#rowObject (readonly)

Returns the value of attribute row.



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

def row
  @row
end

#trObject (readonly)

Returns the value of attribute tr.



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

def tr
  @tr
end

Instance Method Details

#merge?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/spreadsheetkit/row.rb', line 18

def merge?
  merge
end

#render(row) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/spreadsheetkit/row.rb', line 22

def render(row)
  @row = row
  apply_style
  
  @cells.each do |cell|
    cell_x = cell_x(cell)
    
    if merge?
      cell_x.upto(cell_x + cell.additional_columns) do |i| 
        row.set_format(i, cell.format.style)
      end
    else
      row.set_format(cell_x, cell.format.style)
    end
    row[cell_x] = cell.content
  end
end