Class: DesignSystem::Components::Table
- Inherits:
-
Object
- Object
- DesignSystem::Components::Table
- Defined in:
- lib/design_system/components/table.rb
Overview
This is the class to define table component structure
Instance Attribute Summary collapse
-
#caption ⇒ Object
Returns the value of attribute caption.
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#rows ⇒ Object
Returns the value of attribute rows.
Instance Method Summary collapse
- #add_column(content, options = {}) ⇒ Object
- #add_numeric_column(content, options = {}) ⇒ Object
- #add_row(*cells, &block) ⇒ Object
-
#initialize ⇒ Table
constructor
A new instance of Table.
Constructor Details
#initialize ⇒ Table
Returns a new instance of Table.
9 10 11 12 |
# File 'lib/design_system/components/table.rb', line 9 def initialize @columns = [] @rows = [] end |
Instance Attribute Details
#caption ⇒ Object
Returns the value of attribute caption.
7 8 9 |
# File 'lib/design_system/components/table.rb', line 7 def caption @caption end |
#columns ⇒ Object
Returns the value of attribute columns.
7 8 9 |
# File 'lib/design_system/components/table.rb', line 7 def columns @columns end |
#rows ⇒ Object
Returns the value of attribute rows.
7 8 9 |
# File 'lib/design_system/components/table.rb', line 7 def rows @rows end |
Instance Method Details
#add_column(content, options = {}) ⇒ Object
14 15 16 |
# File 'lib/design_system/components/table.rb', line 14 def add_column(content, = {}) @columns << { content:, options: } end |
#add_numeric_column(content, options = {}) ⇒ Object
18 19 20 21 |
# File 'lib/design_system/components/table.rb', line 18 def add_numeric_column(content, = {}) = { type: 'numeric' } @columns << { content:, options: .merge() } end |
#add_row(*cells, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/design_system/components/table.rb', line 23 def add_row(*cells, &block) if block_given? row_builder = TableRowBuilder.new(@columns) block.call(row_builder) @rows << row_builder.cells else row = cells.map.with_index do |content, i| = @columns[i][:options][:type] == 'numeric' ? { type: 'numeric' } : {} { content:, options: } end @rows << row end end |