xcperfect 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 856d2292fad7dc61c02839684c243049a2cf0f2f
4
- data.tar.gz: 16f7d81e204f20d4d41a1aceb2579e48f063ae1e
3
+ metadata.gz: 2314ead27375f324020955f3715ab6857ba356cc
4
+ data.tar.gz: a1afc6fed3d96d64c6e36cc3c27bd2a0ac0be790
5
5
  SHA512:
6
- metadata.gz: c81423d09bdeb9efe680980b4ace5ed652a564beeba4350d86e0a4103f031f654c8e7c27868ad4b3cdfa0d7fe102aa70a10cf0913bd0a3c33bc19c5f04a3faaa
7
- data.tar.gz: b4f2343bf2b639e49a333c55727076bec0b5fda734244981ef68a6ae5eb37f06379b16b6d7571c1119f286f1dabcef455a1c977abf6f4370cc3d33947d04c0d7
6
+ metadata.gz: 69876044da3ecb662dc85ba25e4ceca6c18f8e0efe2db6d4533eb122f1767f7a36b7ab685c98a66a113f162a80526e7a0523cb3492bfada61f5dacb2c762bc40
7
+ data.tar.gz: 57b14bc960f08de8e4b0e36ce62ef33ed13828ab9405874d9b7fa00d98951f4646ccb7c72c95ab5d4517c326a7d7d553f936632a8cd22fa7f7e227a6547f30c3
@@ -0,0 +1,2 @@
1
+ ruby:
2
+ config_file: .rubocop.yml
data/README.md CHANGED
@@ -5,6 +5,9 @@
5
5
  <a href="https://travis-ci.org/mkchoi212/xcperfect">
6
6
  <img src="https://travis-ci.org/mkchoi212/xcperfect.svg?branch=master">
7
7
  </a>
8
+ <a href="https://badge.fury.io/rb/xcperfect">
9
+ <img src="https://badge.fury.io/rb/xcperfect.svg">
10
+ </a>
8
11
  </p>
9
12
  </p>
10
13
  <br>
@@ -17,23 +20,20 @@ $ gem install xcperfect
17
20
 
18
21
  ## Usage
19
22
 
20
- ```bash
21
- $ xcrun xccov --json [options] | xcperfect
22
- ```
23
-
24
- or
23
+ - Pipe
25
24
 
26
25
  ```bash
27
- $ xcrun xccov --json [options] > report.json
28
- $ xcperfect report.json
26
+ $ xcrun xccov --json [options] | xcperfect [options]
29
27
  ```
30
28
 
31
- or
29
+ - Feed it in via flags
32
30
 
33
31
  ```bash
34
32
  $ xcperfect [--file | -f] report.json [options]
35
33
  ```
36
34
 
35
+ > ⚠️ Please note that `xcperfect` only takes in `xccov` json output
36
+
37
37
  ## Formats
38
38
 
39
39
  - `--all`, `-a` **Default**
@@ -1,3 +1,4 @@
1
+ require 'xcperfect/bar'
1
2
  require 'xcperfect/version'
2
3
  require 'xcperfect/printer'
3
4
  require 'xcperfect/parser'
@@ -27,6 +27,19 @@ module XCPerfect
27
27
  !!@colorize
28
28
  end
29
29
 
30
+ def color_for(percentage)
31
+ case (percentage * 100).round
32
+ when 0..33
33
+ ->(x) { red(x) }
34
+ when 33...66
35
+ ->(x) { yellow(x) }
36
+ when 66..100
37
+ ->(x) { green(x) }
38
+ else
39
+ raise "Percentage of #{percentage * 100} is not possible"
40
+ end
41
+ end
42
+
30
43
  def white(text)
31
44
  ansi_parse(text, :plain, :bold)
32
45
  end
@@ -0,0 +1,24 @@
1
+ require 'xcperfect/ansi'
2
+
3
+ module XCPerfect
4
+ # Bar is a "progress bar" that is used to represent
5
+ # the code coverage percentage
6
+ class Bar
7
+ BLOCK = '█'.freeze
8
+ BLOCK_ASCII = '#'.freeze
9
+ extend ANSI
10
+
11
+ def self.create(percentage, bar_length, color, ascii)
12
+ @colorize = color
13
+ block_symbol = ascii ? BLOCK_ASCII : BLOCK
14
+
15
+ progress_length = (bar_length * percentage).round
16
+ filled = block_symbol * progress_length
17
+ remaining = red('-' * (bar_length - progress_length))
18
+
19
+ color_func = color_for(percentage)
20
+ bar = color_func.call(filled) + remaining
21
+ "|#{bar}| #{percentage * 100} %"
22
+ end
23
+ end
24
+ end
@@ -3,6 +3,15 @@ module XCPerfect
3
3
  class All < Formatter
4
4
  DOWN = '▼'.freeze
5
5
  DOWN_ASCII = '->'.freeze
6
+ STAT_WIDTH = 10
7
+
8
+ def bar_width
9
+ ((@terminal_width - 8) * 0.3) - STAT_WIDTH
10
+ end
11
+
12
+ def signature_width
13
+ (@terminal_width - 8) * 0.62
14
+ end
6
15
 
7
16
  def pretty_name(target)
8
17
  symbol = yellow(@use_ascii ? DOWN_ASCII : DOWN)
@@ -12,21 +21,25 @@ module XCPerfect
12
21
  def pretty_functions(file)
13
22
  file['functions'].map do |function|
14
23
  filename = file['name']
15
- signature, covered, total, percentage = pretty_coverage_info(function)
16
- line_stat = [covered, total].join(' / ').ljust(10)
17
- stats = [line_stat, percentage].join("\t\t")
24
+ signature, covered, total, percentage = @parser.extract_coverage_info(function)
25
+
26
+ line_stats = "#{covered} / #{total}".ljust(STAT_WIDTH)
18
27
  highlighted = Syntax.highlight(filename, signature)
28
+
19
29
  delta = highlighted.length - signature.length
20
- fill_size = (@terminal_width / 1.5) + delta
21
- "\t\t" + [highlighted.ljust(fill_size), stats].join(' ')
30
+ highlighted = highlighted.ljust(signature_width + delta)
31
+
32
+ texts = spaces(8) + [highlighted, line_stats].join(' ')
33
+ bar = Bar.create(percentage, bar_width, @colorize, @use_ascii)
34
+ texts + bar
22
35
  end
23
36
  end
24
37
 
25
38
  def pretty_files(target)
26
39
  target['files'].map do |file|
27
- name = "\t" + pretty_name(file)
28
- function = pretty_functions(file)
29
- [name, function]
40
+ name = spaces(4) + pretty_name(file)
41
+ functions = pretty_functions(file)
42
+ [name, functions]
30
43
  end.join("\n")
31
44
  end
32
45
 
@@ -1,4 +1,5 @@
1
1
  require 'xcperfect/ansi'
2
+ require 'xcperfect/bar'
2
3
  require 'xcperfect/parser'
3
4
 
4
5
  module XCPerfect
@@ -19,19 +20,14 @@ module XCPerfect
19
20
  puts @json
20
21
  end
21
22
 
22
- def color_percentage(percentage)
23
- percent_str = percentage.to_s + ' %'
23
+ def spaces(cnt)
24
+ ' ' * cnt
25
+ end
24
26
 
25
- case percentage.round
26
- when 0..33
27
- red(percent_str)
28
- when 33...66
29
- orange(percent_str)
30
- when 66..100
31
- green(percent_str)
32
- else
33
- raise "Percentage of #{percentage} % is not possible :("
34
- end
27
+ def color_percentage(percentage)
28
+ color_func = color_for(percentage)
29
+ str_rep = (percentage * 100).to_s + ' %'
30
+ color_func.call(str_rep)
35
31
  end
36
32
 
37
33
  def pretty_coverage_info(target)
@@ -39,7 +39,7 @@ module XCPerfect
39
39
  end
40
40
 
41
41
  def coverage_percentage(target)
42
- (target['lineCoverage'] * 100).round(2)
42
+ target['lineCoverage'].round(2)
43
43
  end
44
44
 
45
45
  def covered_line_num(target)
@@ -1,5 +1,3 @@
1
- require 'xcperfect/ansi'
2
-
3
1
  module XCPerfect
4
2
  # Printer handles the initialization of the output formatter
5
3
  # and is directly called by the main `xcperfect` file during execution
@@ -1,5 +1,5 @@
1
1
  # VERSION is used in the `Gemfile`, and when displaying the
2
2
  # version to the user via `xcperfect -v`
3
3
  module XCPerfect
4
- VERSION = '0.0.1'.freeze
4
+ VERSION = '0.0.3'.freeze
5
5
  end
@@ -10,10 +10,10 @@ Gem::Specification.new do |spec|
10
10
  spec.required_ruby_version = '>= 2.0.0'
11
11
  spec.description =
12
12
  %q{
13
- Formatter for Apple's xccov json output because who doesn't
13
+ Make your xccov output prettier. Because who doesn't
14
14
  like pretty outputs? Am I rite?
15
15
  }
16
- spec.summary = %q(Make your xccov outputs prettier)
16
+ spec.summary = %q(Better looking xccov reports)
17
17
  spec.homepage = 'https://github.com/mkchoi212/xcperfect'
18
18
  spec.license = 'MIT'
19
19
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcperfect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike JS. Choi
@@ -66,8 +66,8 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.49.0
69
- description: "\n Formatter for Apple's xccov json output because who doesn't\n
70
- \ like pretty outputs? Am I rite?\n "
69
+ description: "\n Make your xccov output prettier. Because who doesn't\n like
70
+ pretty outputs? Am I rite?\n "
71
71
  email:
72
72
  - mkchoi212@icloud.com
73
73
  executables:
@@ -76,6 +76,7 @@ extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
78
  - ".gitignore"
79
+ - ".hound.yml"
79
80
  - ".rubocop.yml"
80
81
  - ".travis.yml"
81
82
  - Gemfile
@@ -89,6 +90,7 @@ files:
89
90
  - bin/xcperfect
90
91
  - lib/xcperfect.rb
91
92
  - lib/xcperfect/ansi.rb
93
+ - lib/xcperfect/bar.rb
92
94
  - lib/xcperfect/formatters/all.rb
93
95
  - lib/xcperfect/formatters/formatter.rb
94
96
  - lib/xcperfect/formatters/simple.rb
@@ -120,5 +122,5 @@ rubyforge_project:
120
122
  rubygems_version: 2.5.2
121
123
  signing_key:
122
124
  specification_version: 4
123
- summary: Make your xccov outputs prettier
125
+ summary: Better looking xccov reports
124
126
  test_files: []