Class: TableSetting::Cell
- Inherits:
-
Object
- Object
- TableSetting::Cell
- Defined in:
- lib/table_setting/cell.rb
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#left_index ⇒ Object
readonly
Returns the value of attribute left_index.
-
#row ⇒ Object
readonly
Returns the value of attribute row.
-
#span ⇒ Object
readonly
Returns the value of attribute span.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
Instance Method Summary collapse
- #background ⇒ Object
- #bold? ⇒ Boolean
- #color ⇒ Object
- #in_column?(number) ⇒ Boolean
-
#initialize(row, contents, options = {}) ⇒ Cell
constructor
A new instance of Cell.
- #preceding_cells ⇒ Object
- #set_style(options) ⇒ Object
- #sheet ⇒ Object
- #size ⇒ Object
- #style_css ⇒ Object
- #style_name ⇒ Object
- #style_xls ⇒ Object
- #to_html ⇒ Object
- #to_xls ⇒ Object
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, = {}) @row = row @row.cells.push(self) @contents = contents @span = [:span] || 1 @style = TableSetting::Style.new(self, ) @left_index = column_index end |
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
2 3 4 |
# File 'lib/table_setting/cell.rb', line 2 def contents @contents end |
#left_index ⇒ Object (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 |
#row ⇒ Object (readonly)
Returns the value of attribute row.
2 3 4 |
# File 'lib/table_setting/cell.rb', line 2 def row @row end |
#span ⇒ Object (readonly)
Returns the value of attribute span.
2 3 4 |
# File 'lib/table_setting/cell.rb', line 2 def span @span end |
#style ⇒ Object (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
#background ⇒ Object
29 30 31 |
# File 'lib/table_setting/cell.rb', line 29 def background @background || row.background end |
#bold? ⇒ Boolean
25 26 27 |
# File 'lib/table_setting/cell.rb', line 25 def bold? @bold || row.bold end |
#color ⇒ Object
33 34 35 |
# File 'lib/table_setting/cell.rb', line 33 def color @color || row.color end |
#in_column?(number) ⇒ Boolean
41 42 43 |
# File 'lib/table_setting/cell.rb', line 41 def in_column?(number) left_index == (number - 1) end |
#preceding_cells ⇒ Object
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() style.update() end |
#sheet ⇒ Object
21 22 23 |
# File 'lib/table_setting/cell.rb', line 21 def sheet row.sheet end |
#size ⇒ Object
37 38 39 |
# File 'lib/table_setting/cell.rb', line 37 def size @size || row.size end |
#style_css ⇒ Object
68 69 70 |
# File 'lib/table_setting/cell.rb', line 68 def style_css style.to_css end |
#style_name ⇒ Object
64 65 66 |
# File 'lib/table_setting/cell.rb', line 64 def style_name style.name end |
#style_xls ⇒ Object
72 73 74 |
# File 'lib/table_setting/cell.rb', line 72 def style_xls style.to_xls_xml end |
#to_html ⇒ Object
58 59 60 61 62 |
# File 'lib/table_setting/cell.rb', line 58 def to_html <<-HTML <td #{html_classes} #{span_attribute}>#{contents.blank? ? ' ' : contents}</td> HTML end |
#to_xls ⇒ Object
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 |