Class: TableSetting::Row

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sheet, options = {}) ⇒ Row

Returns a new instance of Row.



4
5
6
7
8
9
10
11
12
# 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

Instance Attribute Details

#backgroundObject (readonly)

Returns the value of attribute background.



2
3
4
# File 'lib/table_setting/row.rb', line 2

def background
  @background
end

#boldObject (readonly)

Returns the value of attribute bold.



2
3
4
# File 'lib/table_setting/row.rb', line 2

def bold
  @bold
end

#cellsObject

Returns the value of attribute cells.



3
4
5
# File 'lib/table_setting/row.rb', line 3

def cells
  @cells
end

#colorObject (readonly)

Returns the value of attribute color.



2
3
4
# File 'lib/table_setting/row.rb', line 2

def color
  @color
end

#sheetObject (readonly)

Returns the value of attribute sheet.



2
3
4
# File 'lib/table_setting/row.rb', line 2

def sheet
  @sheet
end

#sizeObject (readonly)

Returns the value of attribute size.



2
3
4
# File 'lib/table_setting/row.rb', line 2

def size
  @size
end

Instance Method Details

#add_cells(list) ⇒ Object



36
37
38
# File 'lib/table_setting/row.rb', line 36

def add_cells(list)
  list.map{|contents| self.new_cell(contents)}
end

#bold?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/table_setting/row.rb', line 28

def bold?
  bold
end

#fillObject



59
60
61
62
63
64
65
# File 'lib/table_setting/row.rb', line 59

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?Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
# File 'lib/table_setting/row.rb', line 52

def filled?
  cells.each do |cell|
    return true if cell.span == 'all'
  end
  false
end

#new_cell(contents, options = {}) ⇒ Object



32
33
34
# File 'lib/table_setting/row.rb', line 32

def new_cell(contents, options = {})
  TableSetting::Cell.new(self, contents, options)
end

#num_columnsObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# 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
end

#to_aObject



40
41
42
# File 'lib/table_setting/row.rb', line 40

def to_a
  cells.map(&:contents)
end

#to_htmlObject



44
45
46
47
48
49
50
# File 'lib/table_setting/row.rb', line 44

def to_html
  "    <tr>\n      \#{cells.map(&:to_html).join(\"\\n\")}\n    </tr>\n  HTML\nend\n"

#to_xlsObject



67
68
69
70
71
72
73
# File 'lib/table_setting/row.rb', line 67

def to_xls
  "    <Row>\n      \#{cells.map(&:to_xls).join}\n    </Row>\n  XML\nend\n"