class XCPerfect::Formatter
Formatter
is the base adopted by `all.rb` and `simple.rb`
Attributes
parser[R]
Public Class Methods
new(use_ascii, colorize, json)
click to toggle source
# File lib/xcperfect/formatters/formatter.rb, line 12 def initialize(use_ascii, colorize, json) @use_ascii = use_ascii @colorize = colorize @parser = Parser.new(json) @terminal_width = Integer(`tput cols`) end
Public Instance Methods
align(arrays)
click to toggle source
# File lib/xcperfect/formatters/formatter.rb, line 52 def align(arrays) widths = align_formats(arrays) arrays.map do |row| row.each_with_index.map do |column, idx| column.ljust(widths[idx]) end end end
align_formats(arrays)
click to toggle source
# File lib/xcperfect/formatters/formatter.rb, line 38 def align_formats(arrays) column_sizes = arrays.map(&:length) common_column_size = column_sizes[0] if column_sizes.to_set.length != 1 puts column_sizes raise 'All rows must have same number of columns to be aligned' end (0...common_column_size).map do |column| width = arrays.map { |row| strip(row[column]).length }.max (width * 1.5).round end end
color_percentage(percentage)
click to toggle source
# File lib/xcperfect/formatters/formatter.rb, line 27 def color_percentage(percentage) color_func = color_for(percentage) str_rep = (percentage * 100).to_s + ' %' color_func.call(str_rep) end
pretty_coverage_info(target)
click to toggle source
# File lib/xcperfect/formatters/formatter.rb, line 33 def pretty_coverage_info(target) name, covered, total, percentage = @parser.extract_coverage_info(target) [name, covered.to_s, total.to_s, color_percentage(percentage)] end
pretty_format(___)
click to toggle source
# File lib/xcperfect/formatters/formatter.rb, line 19 def pretty_format(___) puts @json end
spaces(cnt)
click to toggle source
# File lib/xcperfect/formatters/formatter.rb, line 23 def spaces(cnt) ' ' * cnt end