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
- #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
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
28 29 30 |
# File 'lib/table_setting/row.rb', line 28 def bold? bold end |
#fill ⇒ Object
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
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, = {}) 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 end |
#to_a ⇒ Object
40 41 42 |
# File 'lib/table_setting/row.rb', line 40 def to_a cells.map(&:contents) end |
#to_html ⇒ Object
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_xls ⇒ Object
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" |