Class: RODF::Table
Instance Method Summary collapse
- #add_rows(*rows) ⇒ Object
- #column(options = {}) ⇒ Object
- #columns ⇒ Object
- #columns_xml ⇒ Object
- #create_row(*args, &block) ⇒ Object
-
#initialize(title = nil, opts = {}) ⇒ Table
constructor
A new instance of Table.
- #row(options = {}, &contents) ⇒ Object
- #rows ⇒ Object
- #rows_xml ⇒ Object
- #style=(style_name) ⇒ Object
- #xml ⇒ Object
Methods inherited from Container
Constructor Details
#initialize(title = nil, opts = {}) ⇒ Table
Returns a new instance of Table.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rodf/table.rb', line 3 def initialize(title = nil, opts ={}) @title = title @last_row = 0 @elem_attrs = {} @elem_attrs['table:style-name'] = opts[:style] unless opts[:style].nil? @elem_attrs['table:name'] = @title if opts[:attributes] @elem_attrs.merge!(opts[:attributes]) end super end |
Instance Method Details
#add_rows(*rows) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rodf/table.rb', line 53 def add_rows(*rows) if rows.first.first.is_a?(Array) rows = rows.first end rows.each do |row| new_row = self.row new_row.add_cells(row) end end |
#column(options = {}) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/rodf/table.rb', line 69 def column( = {}) x = Column.new() columns << x return x end |
#columns ⇒ Object
65 66 67 |
# File 'lib/rodf/table.rb', line 65 def columns @columns ||= [] end |
#columns_xml ⇒ Object
77 78 79 |
# File 'lib/rodf/table.rb', line 77 def columns_xml columns.map(&:xml).join end |
#create_row(*args, &block) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/rodf/table.rb', line 29 def create_row(*args, &block) x = Row.new(*args, &block) rows << x return x end |
#row(options = {}, &contents) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rodf/table.rb', line 41 def row( = {}, &contents) create_row(next_row, ) do |row| if contents if contents.arity.zero? row.instance_exec(row, &contents) else yield(row) end end end end |
#rows ⇒ Object
25 26 27 |
# File 'lib/rodf/table.rb', line 25 def rows @rows ||= [] end |
#rows_xml ⇒ Object
37 38 39 |
# File 'lib/rodf/table.rb', line 37 def rows_xml rows.map(&:xml).join end |
#style=(style_name) ⇒ Object
21 22 23 |
# File 'lib/rodf/table.rb', line 21 def style=(style_name) @elem_attrs['table:style-name'] = style_name end |
#xml ⇒ Object
81 82 83 84 85 86 |
# File 'lib/rodf/table.rb', line 81 def xml Builder::XmlMarkup.new.table :table, @elem_attrs do |xml| xml << columns_xml xml << rows_xml end end |