Sha256: 38a0021157b98e44a09fe15ffe6e4c5b74fbe74b32793a436f8afcf0ac7a2ee9

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

require "terminal-table"
require_relative "../logger"

module CodeDisplayer
  ##
  # Show all "code" data on screen
  # @param codes (Array) List of "code" data
  def self.show(codes)
    return if codes.nil? || codes.size.zero?

    total_c = total_q = total_e = 0
    my_screen_table = Terminal::Table.new do |st|
      st << %w[Filename Type Questions Lines xFactor]
      st << :separator
    end

    codes.each do |code|
      next unless code.process?

      e = code.lines.size
      q = code.questions.size
      factor = 'Unkown'
      factor = (q.to_f / e).round(2).to_s unless e.zero?
      my_screen_table.add_row [Rainbow(File.basename(code.filename)).green,
                               code.type,
                               q,
                               e,
                               factor]
      total_c += 1
      total_q += q
      total_e += e
    end

    my_screen_table.add_separator
    my_screen_table.add_row [Rainbow("TOTAL = #{total_c}").bright,
                             ' ',
                             Rainbow(total_q.to_s).bright,
                             Rainbow(total_e.to_s).bright,
                             Rainbow((total_q / total_e.to_f).round(2)).bright]
    return unless total_c.positive?

    Logger.verboseln "\n[INFO] Showing CODE statistics"
    Logger.verboseln my_screen_table.to_s
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
asker-tool-2.6.0 lib/asker/displayer/code_displayer.rb
asker-tool-2.5.9 lib/asker/displayer/code_displayer.rb
asker-tool-2.5.8 lib/asker/displayer/code_displayer.rb
asker-tool-2.5.7 lib/asker/displayer/code_displayer.rb
asker-tool-2.5.6 lib/asker/displayer/code_displayer.rb
asker-tool-2.5.5 lib/asker/displayer/code_displayer.rb