Class: CodeDisplayer

Inherits:
Object
  • Object
show all
Defined in:
lib/asker/displayer/code_displayer.rb

Instance Method Summary collapse

Instance Method Details

#call(codes) ⇒ Object

Show all “code” data on screen

Parameters:

  • codes (Array)

    List of “code” data



8
9
10
11
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
38
39
40
41
42
43
44
# File 'lib/asker/displayer/code_displayer.rb', line 8

def call(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