Class: Steep::Drivers::Stats::CSVPrinter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io:) ⇒ CSVPrinter

Returns a new instance of CSVPrinter.



9
10
11
# File 'lib/steep/drivers/stats.rb', line 9

def initialize(io:)
  @io = io
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



7
8
9
# File 'lib/steep/drivers/stats.rb', line 7

def io
  @io
end

Instance Method Details



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
# File 'lib/steep/drivers/stats.rb', line 13

def print(stats_result)
  io.puts(
    CSV.generate do |csv|
      csv << ["Target", "File", "Status", "Typed calls", "Untyped calls", "All calls", "Typed %"]
      stats_result.each do |row|
        if row[:type] == "success"
          # @type var row: Steep::Services::StatsCalculator::SuccessStats::json
          csv << [
            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
          csv << [
            row[:target],
            row[:path],
            row[:type],
            0,
            0,
            0,
            0
          ]
        end
      end
    end
  )
end