123456789_123456789_123456789_123456789_123456789_

Module: SimpleCov::Formatter::HTMLFormatter::ViewHelpers

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Defined in: lib/simplecov/formatter/html_formatter/view_helpers.rb

Overview

Helper methods used by ERB templates for rendering coverage data.

Instance Method Summary

Instance Method Details

#coverage_css_class(covered_percent)

[ GitHub ]

  
# File 'lib/simplecov/formatter/html_formatter/view_helpers.rb', line 36

def coverage_css_class(covered_percent)
  if covered_percent >= 90
    "green"
  elsif covered_percent >= 75
    "yellow"
  else
    "red"
  end
end

#covered_percent(percent)

[ GitHub ]

  
# File 'lib/simplecov/formatter/html_formatter/view_helpers.rb', line 63

def covered_percent(percent)
  template("covered_percent").result(binding)
end

#fmt(number)

[ GitHub ]

  
# File 'lib/simplecov/formatter/html_formatter/view_helpers.rb', line 71

def fmt(number)
  number.to_s.gsub(/(\d)(?=(\d{3})+(?!\d))/, '\\1,')
end

#id(source_file)

[ GitHub ]

  
# File 'lib/simplecov/formatter/html_formatter/view_helpers.rb', line 46

def id(source_file)
  Digest::MD5.hexdigest(source_file.filename)
end

#line_status?(source_file, line) ⇒ Boolean

[ GitHub ]

  
# File 'lib/simplecov/formatter/html_formatter/view_helpers.rb', line 14

def line_status?(source_file, line)
  if branch_coverage? && source_file.line_with_missed_branch?(line.number)
    "missed-branch"
  elsif method_coverage? && missed_method_lines(source_file).include?(line.number)
    "missed-method"
  else
    line.status
  end
end

#missed_method_line_set(source_file)

[ GitHub ]

  
# File 'lib/simplecov/formatter/html_formatter/view_helpers.rb', line 29

def missed_method_line_set(source_file)
  source_file.missed_methods
             .select { |m| m.start_line && m.end_line }
             .flat_map { |m| (m.start_line..m.end_line).to_a }
             .to_set
end

#missed_method_lines(source_file)

[ GitHub ]

  
# File 'lib/simplecov/formatter/html_formatter/view_helpers.rb', line 24

def missed_method_lines(source_file)
  @missed_method_lines ||= {}
  @missed_method_lines[source_file.filename] ||= missed_method_line_set(source_file)
end

#shortened_filename(source_file)

[ GitHub ]

  
# File 'lib/simplecov/formatter/html_formatter/view_helpers.rb', line 54

def shortened_filename(source_file)
  source_file.filename.sub(SimpleCov.root, ".").delete_prefix("./")
end

#timeago(time)

[ GitHub ]

  
# File 'lib/simplecov/formatter/html_formatter/view_helpers.rb', line 50

def timeago(time)
  "<abbr class=\"timeago\" title=\"#{time.iso8601}\">#{time.iso8601}</abbr>"
end

#to_id(value)

[ GitHub ]

  
# File 'lib/simplecov/formatter/html_formatter/view_helpers.rb', line 67

def to_id(value)
  value.sub(/\A[^a-zA-Z]+/, "").gsub(/[^a-zA-Z0-9\-_]/, "")
end