Module: Inch::CLI::SparklineHelper

Included in:
Command::Output::Stats, Command::Output::Suggest
Defined in:
lib/inch/cli/sparkline_helper.rb

Instance Method Summary collapse

Instance Method Details

#__sparkline(list, grade_lists) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/inch/cli/sparkline_helper.rb', line 22

def __sparkline(list, grade_lists)
  sparkline = Sparkr::Sparkline.new(list)
  sparkline.format do |tick, count, index|
    t = tick.color(grade_lists[index].color)
    index == 0 ? t + ' ' : t
  end
end

#grade_lists_sparkline(_grade_lists) ⇒ Object



4
5
6
7
8
# File 'lib/inch/cli/sparkline_helper.rb', line 4

def grade_lists_sparkline(_grade_lists)
  grade_lists = _grade_lists.reverse
  list = grade_lists.map { |r| r.objects.size }
  __sparkline(list, grade_lists)
end

#grades_sparkline(objects) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/inch/cli/sparkline_helper.rb', line 10

def grades_sparkline(objects)
  grades = {}
  objects.each do |o|
    grades[o.grade.to_sym] ||= 0
    grades[o.grade.to_sym] += 1
  end
  grade_lists = Evaluation.new_grade_lists.reverse
  order = grade_lists.map(&:to_sym)
  list = order.map { |g| grades[g] }
  __sparkline(list, grade_lists)
end