class TableSetting::Row

Attributes

background[R]
bold[R]
cells[RW]
color[R]
sheet[R]
size[R]

Public Class Methods

new(sheet, options = {}) click to toggle source
# File lib/table_setting/row.rb, line 4
def initialize(sheet, options = {})
  @sheet = sheet
  @cells = []
  @sheet.rows.push(self)
  @bold       = options[:bold]       || nil
  @background = options[:background] || nil
  @color      = options[:color]      || nil
  @size       = options[:size]       || nil
end

Public Instance Methods

add_cells(list) click to toggle source
# File lib/table_setting/row.rb, line 49
def add_cells(list)
  list.map{|contents| self.new_cell(contents)}
end
bold?() click to toggle source
# File lib/table_setting/row.rb, line 41
def bold?
  bold
end
fill() click to toggle source
# File lib/table_setting/row.rb, line 73
def fill
  if num_columns < sheet.num_columns and
    !filled?
    filler_columns = sheet.num_columns - num_columns
    filler_cell = self.new_cell('', span: filler_columns).to_html
  end
end
filled?() click to toggle source
# File lib/table_setting/row.rb, line 66
def filled?
  cells.each do |cell|
    return true if cell.span == 'all'
  end
  false
end
new_cell(contents, options = {}) click to toggle source
# File lib/table_setting/row.rb, line 45
def new_cell(contents, options = {})
  TableSetting::Cell.new(self, contents, options)
end
num_columns() click to toggle source
# File lib/table_setting/row.rb, line 14
def num_columns
  total_width = 0
  cells.each do |cell|
    width = 1
    if cell.span and 
      cell.span != 'all' and 
      cell.span > 1
      width = cell.span
    end
    total_width += width
  end
  total_width + num_inherited_columns
end
num_inherited_columns() click to toggle source
# File lib/table_setting/row.rb, line 28
def num_inherited_columns
  spanned_columns = 0
  sheet.rows.each do |row|
    row.cells.each do |cell|
      next unless cell.rowspan > 1
      if (sheet.rows.index(row) + (cell.rowspan - 1)) >= sheet.rows.index(self)
        spanned_columns += cell.span
      end
    end
  end
  spanned_columns
end
to_a() click to toggle source
# File lib/table_setting/row.rb, line 53
def to_a
  cells.map(&:contents)
end
to_html() click to toggle source
# File lib/table_setting/row.rb, line 57
  def to_html
    fill
    <<-HTML
      <tr>
        #{cells.map(&:to_html).join("\n")}
      </tr>
    HTML
  end
to_xls() click to toggle source
# File lib/table_setting/row.rb, line 81
  def to_xls
    <<-XML
      <Row>
        #{cells.map(&:to_xls).join}
      </Row>
    XML
  end