class SorbetProgress::Reporters::BarChart
Produces output something like this:
“` Sorbet progress: ignore | false | true | strict+ |—————-50————–|———25——–|-5-|——20——| Keep up the good work 👍 “`
The chart is colored. Colorless terminals are not supported.
Strict and strong are combined into one category because strong is not a reachable goal in most projects.
Constants
- COLORS
- LENGTH
Public Class Methods
new(calculator)
click to toggle source
# File lib/sorbet_progress/reporters/bar_chart.rb, line 28 def initialize(calculator) @calculator = calculator end
Public Instance Methods
report()
click to toggle source
# File lib/sorbet_progress/reporters/bar_chart.rb, line 33 def report [ "Sorbet progress: ignore | false | true | strict+", bar_chart, "Keep up the good work 👍" ].flatten.join("\n") end
Private Instance Methods
bar_chart()
click to toggle source
# File lib/sorbet_progress/reporters/bar_chart.rb, line 44 def bar_chart body = segments.each_with_index.each_with_object([]) { |(e, i), a| a.push(segment(e, i)) }.join("|") format("|%s|", body) end
segment(fraction, index)
click to toggle source
# File lib/sorbet_progress/reporters/bar_chart.rb, line 52 def segment(fraction, index) padding_max = (fraction * LENGTH / 2).round padding_length = [1, padding_max].max pad = "-" * padding_length Rainbow( format("%s%d%s", pad, fraction * 100, pad) ).send(T.must(COLORS[index])) end
segments()
click to toggle source
# File lib/sorbet_progress/reporters/bar_chart.rb, line 62 def segments sigils = sigil_count_by_name [ T.let(sigils.fetch(:sigil_ignore, 0.0), Float), T.let(sigils.fetch(:sigil_false, 0.0), Float), T.let(sigils.fetch(:sigil_true, 0.0), Float), T.let( sigils.fetch(:sigil_strict, 0.0) + sigils.fetch(:sigil_strong, 0.0), Float ) ] end
sigil_count_by_name()
click to toggle source
# File lib/sorbet_progress/reporters/bar_chart.rb, line 76 def sigil_count_by_name @calculator.sigil_percentages.each_with_object({}) { |e, a| a[e.fetch(:label)] = e.fetch(:percentage, 0.0).to_f } end