Sha256: 4a05740b31bb011be48cd02277c5a1b3c48065598c614de06df5fb88682a4e29

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 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 = "Unknown"
      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 CODEs statistics"
    Logger.verboseln my_screen_table.to_s
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
asker-tool-2.7.2 lib/asker/displayer/code_displayer.rb
asker-tool-2.7.1 lib/asker/displayer/code_displayer.rb