Class: Steep::Drivers::Stats::TablePrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/drivers/stats.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io:) ⇒ TablePrinter

Returns a new instance of TablePrinter.



54
55
56
# File 'lib/steep/drivers/stats.rb', line 54

def initialize(io:)
  @io = io
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



52
53
54
# File 'lib/steep/drivers/stats.rb', line 52

def io
  @io
end

Instance Method Details



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/steep/drivers/stats.rb', line 58

def print(stats_result)
  rows = [] #: Array[Array[untyped]]
  stats_result.sort_by {|row| row[:path] }.each do |row|
    if row[:type] == "success"
        # @type var row: Steep::Services::StatsCalculator::SuccessStats::json
        rows << [
        row[:target],
        row[:path] + "  ",
        row[:type],
        row[:typed_calls],
        row[:untyped_calls],
        row[:total_calls],
        if row[:total_calls].nonzero?
          "#{(row[:typed_calls].to_f / row[:total_calls] * 100).to_i}%"
        else
          "100%"
        end
      ]
    else
      # @type var row: Steep::Services::StatsCalculator::ErrorStats::json
      rows << [
        row[:target],
        row[:path],
        row[:type],
        0,
        0,
        0,
        "N/A"
      ]
    end
  end

  table = Terminal::Table.new( # steep:ignore UnknownConstant
    headings: ["Target", "File", "Status", "Typed calls", "Untyped calls", "All calls", "Typed %"],
    rows: rows
  )
  table.align_column(3, :right)
  table.align_column(4, :right)
  table.align_column(5, :right)
  table.align_column(6, :right)
  table.style = { border_top: false, border_bottom: false, border_y: "", border_i: "" }
  io.puts(table)
end