Class: CommandLineReporter::Table
- Inherits:
-
Object
- Object
- CommandLineReporter::Table
- Includes:
- OptionsValidator
- Defined in:
- lib/command_line_reporter/table.rb
Constant Summary collapse
- VALID_OPTIONS =
%i[border width encoding].freeze
Instance Method Summary collapse
- #add(row) ⇒ Object
-
#auto_adjust_widths ⇒ Object
TODO: This doesn’t appear to be used and if it is, it will not handle span appropriately.
-
#initialize(options = {}) ⇒ Table
constructor
A new instance of Table.
-
#output ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/MethodLength.
Methods included from OptionsValidator
Constructor Details
#initialize(options = {}) ⇒ Table
Returns a new instance of Table.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/command_line_reporter/table.rb', line 8 def initialize( = {}) (, *VALID_OPTIONS) self.border = [:border] || false self.width = [:width] || false self.encoding = [:encoding] || CommandLineReporter::DEFAULTS[:encoding] @rows = [] raise ArgumentError, 'Invalid encoding' unless %i[ascii unicode].include? encoding end |
Instance Method Details
#add(row) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/command_line_reporter/table.rb', line 20 def add(row) # Inheritance from the table row.border = border # Inherit properties from the appropriate row inherit_column_attrs(row) if rows[0] rows << row end |
#auto_adjust_widths ⇒ Object
TODO: This doesn’t appear to be used and if it is, it will not handle span appropriately
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/command_line_reporter/table.rb', line 48 def auto_adjust_widths column_widths = [] rows.each do |row| row.columns.each_with_index do |col, i| column_widths[i] = [col.required_width, (column_widths[i] || 0)].max end end rows.each do |row| row.columns.each_with_index do |col, i| col.width = column_widths[i] end end end |
#output ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/MethodLength
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/command_line_reporter/table.rb', line 33 def output return if rows.empty? # we got here with nothing to print to the screen auto_adjust_widths if width == :auto puts separator('first') if border rows.each_with_index do |row, index| row.output puts separator('middle') if border && (index != rows.size - 1) end puts separator('last') if border end |