Class: TableSetting::Cell

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row, contents, options = {}) ⇒ Cell

Returns a new instance of Cell.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/table_setting/cell.rb', line 4

def initialize(row, contents, options = {})
  @row = row
  @row.cells.push(self)

  @contents = contents
  @span     = options[:span] || 1

  @style = TableSetting::Style.new(self, options)

  @left_index = column_index
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



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

def contents
  @contents
end

#left_indexObject (readonly)

Returns the value of attribute left_index.



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

def left_index
  @left_index
end

#rowObject (readonly)

Returns the value of attribute row.



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

def row
  @row
end

#spanObject (readonly)

Returns the value of attribute span.



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

def span
  @span
end

#styleObject (readonly)

Returns the value of attribute style.



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

def style
  @style
end

Instance Method Details

#backgroundObject



29
30
31
# File 'lib/table_setting/cell.rb', line 29

def background
  @background || row.background
end

#bold?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/table_setting/cell.rb', line 25

def bold?
  @bold || row.bold
end

#colorObject



33
34
35
# File 'lib/table_setting/cell.rb', line 33

def color
  @color || row.color
end

#in_column?(number) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/table_setting/cell.rb', line 41

def in_column?(number)
  left_index == (number - 1)
end

#preceding_cellsObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/table_setting/cell.rb', line 45

def preceding_cells
  list = []
  my_index = row.cells.index(self)
  row.cells.each do |cell|
    if row.cells.index(cell) < my_index
      list << cell
    else
      break
    end
  end
  list
end

#set_style(options) ⇒ Object



16
17
18
# File 'lib/table_setting/cell.rb', line 16

def set_style(options)
  style.update(options)
end

#sheetObject



21
22
23
# File 'lib/table_setting/cell.rb', line 21

def sheet
  row.sheet
end

#sizeObject



37
38
39
# File 'lib/table_setting/cell.rb', line 37

def size
  @size || row.size
end

#style_cssObject



68
69
70
# File 'lib/table_setting/cell.rb', line 68

def style_css
  style.to_css
end

#style_nameObject



64
65
66
# File 'lib/table_setting/cell.rb', line 64

def style_name
  style.name
end

#style_xlsObject



72
73
74
# File 'lib/table_setting/cell.rb', line 72

def style_xls
  style.to_xls_xml
end

#to_htmlObject



58
59
60
61
62
# File 'lib/table_setting/cell.rb', line 58

def to_html
  <<-HTML
    <td #{html_classes} #{span_attribute}>#{contents.blank? ? '&nbsp;' : contents}</td>
  HTML
end

#to_xlsObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/table_setting/cell.rb', line 76

def to_xls
  colspan = 1
  if span == 'all'
    colspan = sheet.num_columns
  elsif span
    colspan = span
  end

  if colspan > 1
    column_attribute = %Q{ss:MergeAcross="#{colspan - 1}"}
  end

  %Q{<Cell #{column_attribute} ss:StyleID="#{style.name}"><Data ss:Type="String">#{contents}</Data></Cell>\n}
end