class TableSetting::Cell
Attributes
contents[R]
left_index[R]
row[R]
rowspan[R]
span[R]
style[R]
Public Class Methods
new(row, contents, options = {})
click to toggle source
# 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 @rowspan = options[:rowspan] || 1 @style = TableSetting::Style.new(self, options) @left_index = column_index end
Public Instance Methods
background()
click to toggle source
# File lib/table_setting/cell.rb, line 31 def background @background || row.background end
bold?()
click to toggle source
# File lib/table_setting/cell.rb, line 27 def bold? @bold || row.bold end
color()
click to toggle source
# File lib/table_setting/cell.rb, line 35 def color @color || row.color end
in_column?(number)
click to toggle source
# File lib/table_setting/cell.rb, line 43 def in_column?(number) left_index == (number - 1) end
preceding_cells()
click to toggle source
# File lib/table_setting/cell.rb, line 47 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)
click to toggle source
# File lib/table_setting/cell.rb, line 18 def set_style(options) style.update(options) end
sheet()
click to toggle source
# File lib/table_setting/cell.rb, line 23 def sheet row.sheet end
size()
click to toggle source
# File lib/table_setting/cell.rb, line 39 def size @size || row.size end
style_css()
click to toggle source
# File lib/table_setting/cell.rb, line 75 def style_css style.to_css end
style_name()
click to toggle source
# File lib/table_setting/cell.rb, line 71 def style_name style.name end
style_xls()
click to toggle source
# File lib/table_setting/cell.rb, line 79 def style_xls style.to_xls_xml end
to_html()
click to toggle source
# File lib/table_setting/cell.rb, line 60 def to_html if sheet.debug cell_index = "#{left_index} :: " else cell_index = '' end <<-HTML <td #{html_classes} #{span_attributes}>#{cell_index}#{contents.blank? ? ' ' : contents}</td> HTML end
to_xls()
click to toggle source
# File lib/table_setting/cell.rb, line 83 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
Private Instance Methods
colspan_attribute()
click to toggle source
# File lib/table_setting/cell.rb, line 113 def colspan_attribute span = 1 if @span == 'all' span = sheet.num_columns elsif @span span = @span end if span > 1 return %Q{colspan="#{span}"} end '' end
column_index()
click to toggle source
# File lib/table_setting/cell.rb, line 126 def column_index lefties = preceding_cells if lefties.empty? return 0 end lefties.map{|c| c.span}.sum end
html_classes()
click to toggle source
# File lib/table_setting/cell.rb, line 100 def html_classes return %Q{class="#{style.name}"} unless style.name.blank? end
rowspan_attribute()
click to toggle source
# File lib/table_setting/cell.rb, line 108 def rowspan_attribute return '' unless rowspan and rowspan > 1 %Q{rowspan="#{rowspan}"} end
span_attributes()
click to toggle source
# File lib/table_setting/cell.rb, line 104 def span_attributes %Q{#{rowspan_attribute} #{colspan_attribute}}.strip end