Class: ClassMetrix::Formatters::Components::TableComponent
- Inherits:
-
Object
- Object
- ClassMetrix::Formatters::Components::TableComponent
- Defined in:
- lib/class_metrix/formatters/components/table_component.rb,
lib/class_metrix/formatters/components/table_component/row_processor.rb,
lib/class_metrix/formatters/components/table_component/table_renderer.rb,
lib/class_metrix/formatters/components/table_component/table_data_extractor.rb,
lib/class_metrix/formatters/components/table_component/column_width_calculator.rb
Defined Under Namespace
Classes: ColumnWidthCalculator, RowProcessor, TableDataExtractor, TableRenderer
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(data, options = {}) ⇒ TableComponent
constructor
A new instance of TableComponent.
Constructor Details
#initialize(data, options = {}) ⇒ TableComponent
Returns a new instance of TableComponent.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/class_metrix/formatters/components/table_component.rb', line 12 def initialize(data, = {}) @data = data @options = @expand_hashes = .fetch(:expand_hashes, false) @table_style = .fetch(:table_style, :standard) @min_column_width = .fetch(:min_column_width, 3) @max_column_width = .fetch(:max_column_width, 50) @hide_main_row = .fetch(:hide_main_row, false) @hide_key_rows = .fetch(:hide_key_rows, true) # Default: show only main rows # Initialize helper objects @data_extractor = TableDataExtractor.new(@data[:headers]) @row_processor = RowProcessor.new(@data_extractor, { hide_main_row: @hide_main_row, hide_key_rows: @hide_key_rows }) @width_calculator = ColumnWidthCalculator.new( table_style: @table_style, min_column_width: @min_column_width, max_column_width: @max_column_width ) @renderer = TableRenderer.new( table_style: @table_style, max_column_width: @max_column_width ) end |
Instance Method Details
#generate ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/class_metrix/formatters/components/table_component.rb', line 39 def generate return [""] if @data[:headers].empty? || @data[:rows].empty? headers = @data[:headers] rows = if @expand_hashes @row_processor.(@data[:rows]) else @row_processor.process_simple_rows(@data[:rows]) end column_widths = @width_calculator.calculate_widths(headers, rows) @renderer.render_table(headers, rows, column_widths) end |