Class: ProblemDisplayer

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

Instance Method Summary collapse

Instance Method Details

#call(problems) ⇒ Object

Show all “problem” data on screen

Parameters:

  • problems (Array)

    List of “problems” 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
45
46
47
48
49
50
51
# File 'lib/asker/displayer/problem_displayer.rb', line 8

def call(problems)
  return if problems.nil? || problems.size.zero?

  total_p = total_q = total_e = total_a = total_s = 0
  my_screen_table = Terminal::Table.new do |st|
    st << %w[Problem Desc Questions Entries xFactor a s]
    st << :separator
  end

  problems.each do |problem|
    next unless problem.process?

    e = problem.cases.size
    problem.asks.each do |ask|
      e += ask[:steps].size
      e += 1 if !ask[:answer].nil?
    end

    desc = Rainbow(problem.desc[0, 24]).green
    q = problem.questions.size
    factor = "Unknown"
    factor = (q.to_f / e).round(2).to_s unless e.zero?
    a = problem.stats[:answer]
    s = problem.stats[:steps]

    my_screen_table.add_row [problem.name, desc, q, e, factor, a, s]
    total_p += 1
    total_q += q
    total_e += e
    total_a += a
    total_s += s
  end
  return unless total_p.positive?

  my_screen_table.add_separator
  my_screen_table.add_row [Rainbow("TOTAL = #{total_p}").bright, "",
    Rainbow(total_q.to_s).bright,
    Rainbow(total_e.to_s).bright,
    Rainbow((total_q / total_e.to_f).round(2)).bright,
    Rainbow(total_a.to_s).bright,
    Rainbow(total_s.to_s).bright]
  Logger.verboseln Rainbow("\n[INFO] Showing PROBLEMs statistics").white
  Logger.verboseln my_screen_table.to_s
end