Class: Xcov::Report
Instance Attribute Summary collapse
-
#coverage ⇒ Object
Returns the value of attribute coverage.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#target_templates ⇒ Object
Returns the value of attribute target_templates.
-
#targets ⇒ Object
Returns the value of attribute targets.
Attributes inherited from Base
#coverage_color, #displayable_coverage, #id, #name
Class Method Summary collapse
- .excluded_targets ⇒ Object
- .filter_targets(targets) ⇒ Object
- .included_targets ⇒ Object
-
.map(dictionary) ⇒ Object
Class methods.
Instance Method Summary collapse
- #average_coverage(targets) ⇒ Object
- #html_value ⇒ Object
-
#initialize(targets) ⇒ Report
constructor
A new instance of Report.
- #json_value ⇒ Object
- #markdown_value ⇒ Object
- #print_description ⇒ Object
Methods inherited from Base
#coverage_emoji, #create_coverage_color, #create_displayable_coverage, create_id, #create_summary, template
Constructor Details
#initialize(targets) ⇒ Report
Returns a new instance of Report.
10 11 12 13 14 15 16 |
# File 'lib/xcov/model/report.rb', line 10 def initialize(targets) @targets = targets @coverage = average_coverage(targets) @displayable_coverage = self.create_displayable_coverage @coverage_color = self.create_coverage_color @summary = self.create_summary end |
Instance Attribute Details
#coverage ⇒ Object
Returns the value of attribute coverage.
5 6 7 |
# File 'lib/xcov/model/report.rb', line 5 def coverage @coverage end |
#summary ⇒ Object
Returns the value of attribute summary.
7 8 9 |
# File 'lib/xcov/model/report.rb', line 7 def summary @summary end |
#target_templates ⇒ Object
Returns the value of attribute target_templates.
8 9 10 |
# File 'lib/xcov/model/report.rb', line 8 def target_templates @target_templates end |
#targets ⇒ Object
Returns the value of attribute targets.
6 7 8 |
# File 'lib/xcov/model/report.rb', line 6 def targets @targets end |
Class Method Details
.excluded_targets ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/xcov/model/report.rb', line 94 def self.excluded_targets excluded_targets = Array.new() if Xcov.config[:exclude_targets] if Xcov.config[:exclude_targets].is_a?(Array) excluded_targets = Xcov.config[:exclude_targets] else excluded_targets = Xcov.config[:exclude_targets].split(/\s*,\s*/) end end excluded_targets end |
.filter_targets(targets) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/xcov/model/report.rb', line 68 def self.filter_targets(targets) filtered_targets = Array.new(targets) filtered_targets = filtered_targets.select { |target| !target["name"].include?(".xctest") } if !Xcov.config[:include_test_targets] if Xcov.config[:exclude_targets] filtered_targets = filtered_targets.select { |target| !self.excluded_targets.include?(target["name"])} end if Xcov.config[:include_targets] filtered_targets = filtered_targets.select { |target| self.included_targets.include?(target["name"])} end filtered_targets = filtered_targets.select { |target| !target["files"].empty? } supported_targets = Xcov.config[:is_swift_package] ? [] : Xcov.project.targets if Xcov.config[:only_project_targets] && !supported_targets.empty? filtered_targets = filtered_targets.select do |target| name = target["name"] name.slice! File.extname(name) # remove target extensions supported_targets.include?(name) end end filtered_targets end |
.included_targets ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/xcov/model/report.rb', line 108 def self.included_targets included_targets = Array.new() if Xcov.config[:include_targets] if Xcov.config[:include_targets].is_a?(Array) included_targets = Xcov.config[:include_targets] else included_targets = Xcov.config[:include_targets].split(/\s*,\s*/) end end included_targets end |
.map(dictionary) ⇒ Object
Class methods
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/xcov/model/report.rb', line 55 def self.map(dictionary) targets = Report.filter_targets dictionary["targets"] # Create target objects targets = targets.map { |target| Target.map(target) }.sort { |lhs, rhs| lhs.name <=> rhs.name } if !Xcov.config[:include_zero_targets] targets = targets.select { |target| target.coverage > 0 } end Report.new(targets) end |
Instance Method Details
#average_coverage(targets) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/xcov/model/report.rb', line 18 def average_coverage targets return 0 if targets.count == 0 return targets.first.coverage if targets.count == 1 acc_coverage = targets.reduce(0) { |acc, target| acc + target.coverage } acc_coverage.to_f / targets.count end |
#html_value ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/xcov/model/report.rb', line 33 def html_value @target_templates = "" @targets.each do |target| @target_templates << target.html_value end Function.template("report").result(binding) end |
#json_value ⇒ Object
46 47 48 49 50 51 |
# File 'lib/xcov/model/report.rb', line 46 def json_value { "coverage" => @coverage, "targets" => @targets ? @targets.map{ |target| target.json_value } : [] } end |
#markdown_value ⇒ Object
42 43 44 |
# File 'lib/xcov/model/report.rb', line 42 def markdown_value "#{@targets.map { |target| target.markdown_value }.join("")}\n> Powered by [xcov](https://github.com/nakiostudio/xcov)" end |
#print_description ⇒ Object
26 27 28 29 30 31 |
# File 'lib/xcov/model/report.rb', line 26 def print_description puts "Total coverage: (#{@coverage})" @targets.each do |target| target.print_description end end |