Class: XCPerfect::Bar

Inherits:
Object
  • Object
show all
Extended by:
ANSI
Defined in:
lib/xcperfect/bar.rb

Overview

Bar is a “progress bar” that is used to represent the code coverage percentage

Constant Summary collapse

BLOCK =
''.freeze
BLOCK_ASCII =
'#'.freeze

Constants included from ANSI

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

Instance Attribute Summary

Attributes included from ANSI

#colorize

Class Method Summary collapse

Methods included from ANSI

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

Class Method Details

.create(percentage, bar_length, color, ascii) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/xcperfect/bar.rb', line 11

def self.create(percentage, bar_length, color, ascii)
  @colorize = color
  block_symbol = ascii ? BLOCK_ASCII : BLOCK

  progress_length = (bar_length * percentage).round
  filled = block_symbol * progress_length
  remaining = red('-' * (bar_length - progress_length))

  color_func = color_for(percentage)
  bar = color_func.call(filled) + remaining
  "|#{bar}| #{percentage * 100} %"
end