Class: TableSetting::Row
- Inherits:
-
Object
- Object
- TableSetting::Row
- Defined in:
- lib/table_setting/row.rb
Instance Attribute Summary collapse
-
#background ⇒ Object
readonly
Returns the value of attribute background.
-
#bold ⇒ Object
readonly
Returns the value of attribute bold.
-
#cells ⇒ Object
Returns the value of attribute cells.
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#sheet ⇒ Object
readonly
Returns the value of attribute sheet.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #add_cells(list) ⇒ Object
- #bold? ⇒ Boolean
- #fill ⇒ Object
- #filled? ⇒ Boolean
-
#initialize(sheet, options = {}) ⇒ Row
constructor
A new instance of Row.
- #new_cell(contents, options = {}) ⇒ Object
- #num_columns ⇒ Object
- #num_inherited_columns ⇒ Object
- #to_a ⇒ Object
- #to_html ⇒ Object
- #to_xls ⇒ Object
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, = {}) @sheet = sheet @cells = [] @sheet.rows.push(self) @bold = [:bold] || nil @background = [:background] || nil @color = [:color] || nil @size = [:size] || nil end |
Instance Attribute Details
#background ⇒ Object (readonly)
Returns the value of attribute background.
2 3 4 |
# File 'lib/table_setting/row.rb', line 2 def background @background end |
#bold ⇒ Object (readonly)
Returns the value of attribute bold.
2 3 4 |
# File 'lib/table_setting/row.rb', line 2 def bold @bold end |
#cells ⇒ Object
Returns the value of attribute cells.
3 4 5 |
# File 'lib/table_setting/row.rb', line 3 def cells @cells end |
#color ⇒ Object (readonly)
Returns the value of attribute color.
2 3 4 |
# File 'lib/table_setting/row.rb', line 2 def color @color end |
#sheet ⇒ Object (readonly)
Returns the value of attribute sheet.
2 3 4 |
# File 'lib/table_setting/row.rb', line 2 def sheet @sheet end |
#size ⇒ Object (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
49 50 51 |
# File 'lib/table_setting/row.rb', line 49 def add_cells(list) list.map{|contents| self.new_cell(contents)} end |
#bold? ⇒ Boolean
41 42 43 |
# File 'lib/table_setting/row.rb', line 41 def bold? bold end |
#fill ⇒ Object
73 74 75 76 77 78 79 |
# 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? ⇒ Boolean
66 67 68 69 70 71 |
# 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 = {}) ⇒ Object
45 46 47 |
# File 'lib/table_setting/row.rb', line 45 def new_cell(contents, = {}) TableSetting::Cell.new(self, contents, ) end |
#num_columns ⇒ Object
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 + num_inherited_columns end |
#num_inherited_columns ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# 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 ⇒ Object
53 54 55 |
# File 'lib/table_setting/row.rb', line 53 def to_a cells.map(&:contents) end |
#to_html ⇒ Object
57 58 59 60 61 62 63 64 |
# 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 ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/table_setting/row.rb', line 81 def to_xls <<-XML <Row> #{cells.map(&:to_xls).join} </Row> XML end |