Class: StyleStats::Template::Table

Inherits:
Object
  • Object
show all
Includes:
CommandLineReporter
Defined in:
lib/style_stats/templates/table.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Table

Returns a new instance of Table.



5
6
7
# File 'lib/style_stats/templates/table.rb', line 5

def initialize(hash)
  @hash = hash
end

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/style_stats/templates/table.rb', line 9

def run
  table(width: :auto, border: true) do
    @hash.each do |key, value|
      if value.is_a?(Array)
        value.each_with_index do |item, index|
          row(separate: index == value.count - 1) do
            column(index.zero? ? key : '', color: :red)
            column(item)
          end
        end
      else
        row do
          column(key, color: :red)
          column(value)
        end
      end
    end
  end
end