Class: XCPerfect::All

Inherits:
Formatter show all
Defined in:
lib/xcperfect/formatters/all.rb

Overview

All prints all code coverage information provided by xccov

Constant Summary collapse

DOWN =
'▼'.freeze
DOWN_ASCII =
'->'.freeze
STAT_WIDTH =
10

Constants included from ANSI

XCPerfect::ANSI::COLORS, XCPerfect::ANSI::EFFECT, XCPerfect::ANSI::FORMATTED_MATCHER

Instance Attribute Summary

Attributes inherited from Formatter

#parser

Attributes included from ANSI

#colorize

Instance Method Summary collapse

Methods inherited from Formatter

#align, #align_formats, #color_percentage, #initialize, #pretty_coverage_info, #spaces

Methods included from ANSI

#ansi_parse, #applied_effects, #color_for, #colorize?, #cyan, #green, #red, #strip, #white, #yellow

Constructor Details

This class inherits a constructor from XCPerfect::Formatter

Instance Method Details

#bar_widthObject



8
9
10
# File 'lib/xcperfect/formatters/all.rb', line 8

def bar_width
  ((@terminal_width - 8) * 0.3) - STAT_WIDTH
end

#pretty_files(target) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/xcperfect/formatters/all.rb', line 38

def pretty_files(target)
  target['files'].map do |file|
    name = spaces(4) + pretty_name(file)
    functions = pretty_functions(file)
    [name, functions]
  end.join("\n")
end

#pretty_format(desirables) ⇒ Object



46
47
48
49
50
# File 'lib/xcperfect/formatters/all.rb', line 46

def pretty_format(desirables)
  @parser.extract_targets(desirables).map do |target|
    [pretty_name(target), pretty_files(target)]
  end.join("\n")
end

#pretty_functions(file) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/xcperfect/formatters/all.rb', line 21

def pretty_functions(file)
  file['functions'].map do |function|
    filename = file['name']
    signature, covered, total, percentage = @parser.extract_coverage_info(function)

    line_stats = "#{covered} / #{total}".ljust(STAT_WIDTH)
    highlighted = Syntax.highlight(filename, signature)

    delta = highlighted.length - signature.length
    highlighted = highlighted.ljust(signature_width + delta)

    texts = spaces(8) + [highlighted, line_stats].join(' ')
    bar = Bar.create(percentage, bar_width, @colorize, @use_ascii)
    texts + bar
  end
end

#pretty_name(target) ⇒ Object



16
17
18
19
# File 'lib/xcperfect/formatters/all.rb', line 16

def pretty_name(target)
  symbol = yellow(@use_ascii ? DOWN_ASCII : DOWN)
  [symbol, white(target['name'])].join(' ')
end

#signature_widthObject



12
13
14
# File 'lib/xcperfect/formatters/all.rb', line 12

def signature_width
  (@terminal_width - 8) * 0.62
end