class Xcov::Report

Attributes

coverage[RW]
summary[RW]
target_templates[RW]
targets[RW]

Public Class Methods

excluded_targets() click to toggle source
# File lib/xcov/model/report.rb, line 88
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) click to toggle source
# File lib/xcov/model/report.rb, line 64
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

  supported_targets = 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() click to toggle source
# File lib/xcov/model/report.rb, line 102
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) click to toggle source

Class methods

# 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 }

  Report.new(targets)
end
new(targets) click to toggle source
# 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

Public Instance Methods

average_coverage(targets) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/xcov/model/report.rb, line 46
def json_value
    {
      "coverage" => @coverage,
      "targets" => @targets ? @targets.map{ |target| target.json_value } : []
    }
end
markdown_value() click to toggle source
# 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() click to toggle source